Page 1 of 1

filtering SQL table results

Posted: Wed Nov 26, 2008 9:51 pm
by matt1234
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>&nbsp;&nbsp;' . $row['username'] . '&nbsp;&nbsp;</i></font>';
echo '<br><br>';
}
else if ($row['variable'] == '') {
echo '<font face="Arial" size="2" color="#FF0000">';
echo '<i>&nbsp;&nbsp;' . $row['username'] . '&nbsp;&nbsp;</i></font>';
echo '<br><br>';
}
else {
}
}

Re: filtering SQL table results

Posted: Wed Nov 26, 2008 11:10 pm
by pcoder
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

Re: filtering SQL table results

Posted: Fri Nov 28, 2008 7:54 pm
by matt1234
Ok, now I got them all to equal 1 and the text is still red. Any suggestions?

Re: filtering SQL table results

Posted: Fri Nov 28, 2008 8:33 pm
by requinix
Are you sure that it's only the string "1"?

var_dump($row["variable"]) should give you

Code: Select all

string(1) "1"
Almost anything else will make the text red.