0

我的查询不断给出

警告:mysql_num_rows() 期望参数 1 是资源,给定的布尔值

这 2 行的错误:

$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 然后在动态表中列出结果。查询的表是“pages”和“campaigns”,我试图分别将“campaignid”列与“id”列匹配。

谢谢你的帮助!

4

3 回答 3

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);
于 2012-05-18T08:16:05.697 回答
-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;";
于 2012-05-18T08:14:37.927 回答
-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)
于 2012-05-18T08:16:25.357 回答