mysql_num_rows()在我的查询中抛出错误

时间:2012-05-18 08:06:58

标签: php mysql

我的查询不断给出

  

警告:mysql_num_rows()期望参数1为资源,布尔值为

这两行有错误

$num_pgs = mysql_num_rows($camp_pgs);
            $num_cid = mysql_num_rows($camp_id);

在此声明中:

$userID=PageDB::getInstance()->get_user_id_by_name($_SESSION['user']);
            $result_pg=mysql_query("SELECT * FROM pages where campaign=" . $campaignID); 
            $result_cid=mysql_query("SELECT * FROM campaign where id=" . $campaignID); 
            $camp_pgs = mysql_query($result_pg);
            $camp_id = mysql_query($result_cid);
            $num_pgs = mysql_num_rows($camp_pgs);
            $num_cid = mysql_num_rows($camp_id);
            $i=0;
                        if ($num_pgs > 0){
                while ($row = mysqli_fetch_array($camp_pgs)):
                 $style = "";
                    if($i%2==0)

我在这里想要的是匹配来自2个单独表的2列,其中如果table.column 1 = table.column 2则将结果列在动态表中。 查询的表格是“页面”和“广告系列”,我试图将列“campaignid”与列“id”分别匹配。

感谢您的帮助!

3 个答案:

答案 0 :(得分:1)

替换

 $num_pgs = mysql_num_rows($camp_pgs);
 $num_cid = mysql_num_rows($camp_id);

$num_pgs = mysql_num_rows( $result_pg);
$num_cid = mysql_num_rows($result_cid);

删除:

 $camp_pgs = mysql_query($result_pg);
 $camp_id = mysql_query($result_cid);

答案 1 :(得分:-1)

$query = "SELECT * FROM pages, campaign WHERE campaign='".$campaignID."' AND campaign=id;";


// guess you have column "id" in both tables - then use this line
$query = "SELECT * FROM pages AS p, campaign AS c WHERE c.campaign='".$campaignID."' AND c.campaign=p.id;";

答案 2 :(得分:-1)

尝试以下代码,

$userID=PageDB::getInstance()->get_user_id_by_name($_SESSION['user']);
        $result_pg=("SELECT * FROM pages where campaign=" . $campaignID); 
        $result_cid=("SELECT * FROM campaign where id=" . $campaignID); 
        $camp_pgs = mysql_query($result_pg);
        $camp_id = mysql_query($result_cid);
        $num_pgs = mysql_num_rows($camp_pgs);
        $num_cid = mysql_num_rows($camp_id);
        $i=0;
                    if ($num_pgs > 0){
            while ($row = mysqli_fetch_array($camp_pgs)):
             $style = "";
                if($i%2==0)