mysql_numrows()期望参数1是资源

时间:2013-02-08 07:29:32

标签: mysql sql

我已设置此查询,我从我的数据库中筛选出一些结果。 它实际上显示了应该的方式 - 但我仍然得到这个错误:

“警告:mysql_numrows()期望参数1是资源,字符串在......”

中给出

我的问题是什么? ; - )

$dblink = mysqli_connect("localhost", "*", "*", "*") or die ("Fejl: Kan ikke etablere forbindelse til databasen..");
        $query= "SELECT * FROM udgivelse";
        $count= mysql_numrows($query);

        $query2= "SELECT * FROM (SELECT release_id, release_pic, release_artist, release_title, release_info, release_tracks, release_catalognr, beatportlink, ituneslink, traxsourcelink,                  alternativelink FROM udgivelse ORDER BY release_id ASC LIMIT "+$count-3+";) ORDER BY release_id DESC;";


        $oldrelease = mysqli_query($dblink, $query) or die( "Forespørgslen kunne ikke udføres: " . mysqli_error($dblink));

提前致谢!

3 个答案:

答案 0 :(得分:1)

$query = "SELECT * FROM udgivelse";
$count= mysql_numrows(mysql_query($query));

问题出在QUERY 2上,子查询应该有ALIAS

$query2= "  SELECT * 
            FROM 
                (SELECT release_id, 
                        release_pic, 
                        release_artist, 
                        release_title, 
                        release_info, 
                        release_tracks, 
                        release_catalognr, 
                        beatportlink, 
                        ituneslink, 
                        traxsourcelink,                  
                        alternativelink 
                FROM    udgivelse 
                ORDER BY release_id ASC 
                LIMIT " . $count-3 .") xx
            ORDER BY release_id DESC; ";

答案 1 :(得分:1)

$query= "SELECT * FROM udgivelse"; need to execute using mysql_query. 

//use this

$query= mysql_query("SELECT * FROM udgivelse"); 
$numrows = mysql_num_rows($query);

答案 2 :(得分:0)

与警告消息一样,mysql_num_rows不希望查询字符串作为参数,而是资源句柄(mysql_query调用的返回值)。

请参阅下面的代码(来自php.net):

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";