Warning: mysql_fetch_array() ?

Discussion in 'PHP' started by izlik, Dec 9, 2007.

  1. #1
    why do this code bellow give me this error ?

    
    <?php
    require_once("global.php");
    
    $sql = "SELECT id FROM users ORDER BY today DESC LIMIT 1";
    $result = mysql_fetch_array($sql);
    $update_user = mysql_query("update users set featured = featured + 1 where userid = " . $result["id"] . " 
    
    limit 1");
          
    
    ?> 
    PHP:

     
    izlik, Dec 9, 2007 IP
  2. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #2
    You are missing a mysql_query:

    
    $sql = "SELECT id FROM users ORDER BY today DESC LIMIT 1";
    mysql_query($sql);
    $result = mysql_fetch_array($sql);
    
    PHP:
     
    theOtherOne, Dec 9, 2007 IP
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    ok, so now it looks like this and still errors me :/

    
    <?php
    require_once("global.php");
    
    $sql = "SELECT id FROM users ORDER BY today DESC LIMIT 1";
    mysql_query($sql);
    $result = mysql_fetch_array($sql);
    $update_user = mysql_query("update users set featured = featured + 1 where userid = " . $result["id"] . "
    
    limit 1");
         
    
    ?>
    PHP:
     
    izlik, Dec 9, 2007 IP
  4. danzor

    danzor Peon

    Messages:
    208
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    require_once("global.php");
    
    $sql = mysql_query("SELECT id FROM users ORDER BY today DESC LIMIT 1");
    $result = mysql_fetch_array($sql);
    $update_user = mysql_query("update users set featured = featured + 1 where userid = " . $result["id"] . "
    
    limit 1");
    
    ?>
    PHP:
     
    danzor, Dec 9, 2007 IP
  5. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #5
    still get the error :/

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /test.php on line 5
     
    izlik, Dec 9, 2007 IP
  6. danzor

    danzor Peon

    Messages:
    208
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #6
    there must be something wrong with your query then.

    
    <?php
    require_once("global.php");
    
    $sql = mysql_query("SELECT id FROM users ORDER BY today DESC LIMIT 1") or die (mysql_error());
    $result = mysql_fetch_array($sql);
    $update_user = mysql_query("update users set featured = featured + 1 where userid = " . $result["id"] . " limit 1");
    
    ?>
    
    PHP:
    That'll tell you the mysql error.
     
    danzor, Dec 9, 2007 IP
  7. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #7
    I knew something was missing in my fix... sorry :)
     
    theOtherOne, Dec 9, 2007 IP
  8. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #8
    aw.... i had spelled on of the collumns wrong >.< i should learn to read...

    anyhow, thank you all for the help! :)
     
    izlik, Dec 9, 2007 IP