Hi All
I have a while loop and array. I want to run an if else statement in it to be used in the final result:
$result_array[] = "
if (".$_SERVER['REQUEST_URI']." == '/".$row[2]."') {
echo(' <img src='/images/2dots.gif' width='8' height='8' align='absmiddle'> <span class='whitetext'>".$row[1]."</span><br>
<img src='/images/spacer.gif' alt='' border='0' width='1' height='10'><br>
');
} else {
echo(' <img src='/images/2dots.gif' width='8' height='8' align='absmiddle'> <a href='".$row[2]."'>".$row[1]."</a><br>
<img src='/images/spacer.gif' alt='' border='0' width='1' height='10'><br>');
}
";
Where I want it displayed I am using the following in an echo statement:
eval('?>' . $result_final);
If I use my if/else statement by itself it works fine but as I am using it now it does not parse.
Can anyone help?
Many Thanks
mrmbarnes
parse as php in a while loop array
Moderator: General Moderators
you need to use eval() properly
http://php.net/eval
but, eval is almost never the best way to solve a problem
the person who started php before it went open source, said:
"if eval is the answer, your almost certainly asking the wrong question"
id recomend you learn how to use functions, or devise another way to do it.
http://php.net/eval
but, eval is almost never the best way to solve a problem
the person who started php before it went open source, said:
"if eval is the answer, your almost certainly asking the wrong question"
id recomend you learn how to use functions, or devise another way to do it.
we need more info, more code etc..
also, please use
also, please use
Code: Select all
tags
why cant you just do this?Code: Select all
// psuedo code
while (row = sql_result) {
if (condition) {
echo "something $var";
}
}OK
Your help is greatly appreciated with this. I am trying to build a sidenav that will change the colour of the link depending on the url so you know which section you are in.
The sql I am using is:
The if/else php is:
The full code I am currently using is:
I need to learn more to get this going and your help is helping.
Mnay Thanks
mrmbarnes
Your help is greatly appreciated with this. I am trying to build a sidenav that will change the colour of the link depending on the url so you know which section you are in.
The sql I am using is:
Code: Select all
$result = mysql_query( "SELECT navid, text, link
FROM nav
ORDER BY navid asc
" );Code: Select all
if ("".$_SERVER['REQUEST_URI']."" == '".$row[1]."') {
echo(" <img src='/images/2dots.gif' width='8' height='8' align='absmiddle'> <span class='whitetext'>".$row[1]."</span><br>
<img src='/images/spacer.gif' alt='' border='0' width='1' height='10'><br>
");
} else {
echo(" <img src='/images/2dots.gif' width='8' height='8' align='absmiddle'> <a href='".$row[2]."'>".$row[1]."</a><br>
<img src='/images/spacer.gif' alt='' border='0' width='1' height='10'><br>");
}Code: Select all
$result_array = array();
$counter = 0;
$PID = (int)($_GET['PID4']);
if( empty($PID))
{
$result = mysql_query( "SELECT navid, text, link
FROM nav
ORDER BY navid asc
" );
while( $row = mysql_fetch_array( $result ) )
{
$result_array[] = "
if ('".$_SERVER['REQUEST_URI']."' == '".$row[2]."') {
echo(' <img src='/images/2dots.gif' width='8' height='8' align='absmiddle'> <span class='whitetext'>".$row[1]."</span><br>
<img src='/images/spacer.gif' alt='' border='0' width='1' height='10'><br>
');
} else {
echo(' <img src='/images/2dots.gif' width='8' height='8' align='absmiddle'> <a href='".$row[2]."'>".$row[1]."</a><br>
<img src='/images/spacer.gif' alt='' border='0' width='1' height='10'><br>');
}
";
}
mysql_free_result( $result );
$result_final = "";
foreach($result_array as $page_link)
{
if($counter == $number_of_categories_in_row)
{
$counter = 1;
$result_final .= "";
}
else
$counter++;
$result_final .= "".$page_link."";
}
}
echo ("
<table width='100%' border='0' cellspacing='2' cellpadding='2'>
<tr>
<td>
<p>
<img src='/images/spacer.gif' alt='' border='0' width='1' height='10'><br>");
eval('?>' . $result_final);
echo ("</p>
</td>
</tr>
</table>
");Mnay Thanks
mrmbarnes
Code: Select all
if ($_SERVER['REQUEST_URI'] == $row[1]) {
echo "foo";
}