MySQL & PHP Parameter 1 as Resource

后端 未结 3 1574
北荒
北荒 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

提交回复
热议问题