I am trying to filter results from a SQL table where if the result is one thing, it prints in black and if it's another, it prints in red. I can't figure out why this is not working because I saw the same setup of code on someone's website when they were trying to explain how to do it.. My problem is that it prints the results but all in red. When I was testing it, the SQL table said a couple of them should have printed out black.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
extract($row);
if ($row['variable'] == '1') {
echo '<font face="Arial" size="2" color="#000000">';
echo '<i> ' . $row['username'] . ' </i></font>';
echo '<br><br>';
}
else if ($row['variable'] == '') {
echo '<font face="Arial" size="2" color="#FF0000">';
echo '<i> ' . $row['username'] . ' </i></font>';
echo '<br><br>';
}
else {
}
}
filtering SQL table results
Moderator: General Moderators
Re: filtering SQL table results
First of all , check out the data populated from your query.
Then only go for the other condition. In your case, check out the $row array.
This will help you to debug your problem.
And please don't forget to put your code inside a proper tag.
Cheers
Then only go for the other condition. In your case, check out the $row array.
This will help you to debug your problem.
And please don't forget to put your code inside a proper tag.
Cheers
Re: filtering SQL table results
Ok, now I got them all to equal 1 and the text is still red. Any suggestions?
Re: filtering SQL table results
Are you sure that it's only the string "1"?
var_dump($row["variable"]) should give you
Almost anything else will make the text red.
var_dump($row["variable"]) should give you
Code: Select all
string(1) "1"