PDA

View Full Version : HELP!! Conditional Statement



MadHacker
April 22, 2005, 08:09 PM
hey I have a conditional statement

<?php
$test=$_GET["view"];
if ($test=="web"){ ?>

****inserted in this space is a table I want to display *****


<?php }?>

Ok here is the problem the above code will display the text properly if the url is Test.php?view="web" but I want it to show if the url is Test.php?view=all also

Need help like tonight :eusa_pray

death_knight
April 22, 2005, 11:30 PM
so use an or statment then. || so either of em that passes will show the table. you did say you wanna show the same table right weather ther what is being passed over in the GET array is "all" or "web"

Virus_NCU
April 22, 2005, 11:51 PM
Use two functions, 1 for displaying table containing web content and the other displaying other content.

function displaywebcontent()
{
echo "<table>";..............etc. **create your table to display web content**
echo "</table>";
}

function displayothercontent()
{
echo "<table>";..............etc. **create your table to display web content**
echo "</table>";
}

if($_REQUEST["view"]=="web")
displaywebcontent();
else
{
displaywebcontent();
displayothercontent();
}

MadHacker
April 23, 2005, 12:21 AM
<html>
<head>
<title>Helper</title>
</head>
<body>
<?php
function displaywebcontent()
{
?>
<table width="75%" border="0">
<tr>
<td>WEb content</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
</tr>
</table>

<?php
}
function displayother()
{
?>
<table width="75%" border="0">
<tr>
<td>Other content</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>a</td>
<td>a</td>
</tr>
<tr>
<td>b</td>
<td>b</td>
</tr>
<tr>
<td>c</td>
<td>c</td>
</tr>
</table>

<?php
}
/* It will show the web content if the url is youpage.php?view=web
if the document is saved as yourpage.php */
if($_REQUEST["view"]=="web")
{
displaywebcontent();
}
elseif($_REQUEST["view"]=="all")
{
displaywebcontent();
displayother();
}
else
{
echo "damit nothing!";
}
?>
</body>
</html>
the code above did the job

NB THANKS VIRUS_NCU

death_knight
April 23, 2005, 12:43 AM
as i figured it wasnt a situation whre you wanted the same table if it was just one table a simple or operator in an if statemnt would work.

Virus_NCU
April 23, 2005, 07:35 AM
Your most welcome. http://techhelpers.net/e4u/drink/trink39.gif