filtering SQL table results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
matt1234
Forum Commoner
Posts: 44
Joined: Wed Nov 26, 2008 9:43 pm

filtering SQL table results

Post 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 {
}
}
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: filtering SQL table results

Post 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
matt1234
Forum Commoner
Posts: 44
Joined: Wed Nov 26, 2008 9:43 pm

Re: filtering SQL table results

Post by matt1234 »

Ok, now I got them all to equal 1 and the text is still red. Any suggestions?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: filtering SQL table results

Post 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.
Post Reply