PDA

View Full Version : if....



onestopplay
07-13-2009, 11:28 AM
This has been driving me CRAZY ever since I started working with PHP/MySQL.
Basically I need the code to connect to database, have a mysql_query statement with the whole SELECT * FROM .....
Now I then use $result = mysql_fetch_array. Whether or not I should use this is what I'm asking. But I need an if statement that basically says in simple terms:
if $var is not any of the rows in $result
{
//code
}
I could say
if $var != $result but that only works for one row in the database.

forum_amnesiac
07-13-2009, 02:10 PM
This is how I would do the query and then the if statatement


$result = mysql_query("SELECT * FROM ..... ORDER BY ......")
You can find the number of rows selected by
$num=mysql_num_rows($result);

You can then do a while loop


$x=0;
while ($x < $num) {

put your if statement in here and close the while loop like this


$x++;
}