Results 1 to 2 of 2

Thread: if....

  1. #1
    Join Date
    Jun 2009
    Posts
    62
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default if....

    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.

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    This is how I would do the query and then the if statatement

    PHP Code:
    $result mysql_query("SELECT * FROM ..... ORDER BY ......"
    You can find the number of rows selected by
    PHP Code:
    $num=mysql_num_rows($result); 
    You can then do a while loop

    PHP Code:
    $x=0;
    while (
    $x $num) { 
    put your if statement in here and close the while loop like this

    PHP Code:
    $x++;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •