MySQL & PHP Parameter 1 as Resource

后端 未结 3 1571
北荒
北荒 2020-12-02 02:22

Alright, PHP is throwing this error at me (in the log) when I run the code mentioned below:

Error

mysql_num_rows() expects pa

相关标签:
3条回答
  • 2020-12-02 02:41

    As it been said, you're missing mysql_query function.
    Though whole approach is wrong. You shouldn't select whole load of ata if you need only number of rows.
    So, it must be

    $sql = "SELECT count(*) FROM db";
    $res = mysql_query($sql) or trigger_error(mysql_error().$sql);
    $row = mysql_fetch_row($res);
    $countFP = $row[0];
    $aID = rand(1, $countFP);
    

    And I hope you won't use $aID for any database related action

    0 讨论(0)
  • 2020-12-02 02:53

    You are missing the mysql_query function, it should be like this:

    $queryFP = "SELECT * FROM table_name_here";
    $queryFP = mysql_query($queryFP) or die(mysql_error());
    $countFP = mysql_num_rows($queryFP);
    $aID = rand(1, $countFP);
    
    0 讨论(0)
  • 2020-12-02 03:00

    You need to query the database first.

    $queryFP = ("SELECT * FROM db");
    

    Should be:

    $queryFP = mysql_query("SELECT * FROM db");
    
    0 讨论(0)
提交回复
热议问题