douyue2313 2012-05-18 12:15
浏览 20

显示正确的结果,但我想将它们限制为相同的值

I have this query which shows my "pages" in a dynamic table, however it shows all of the pages, I want to limit the "pages" to show only if their "campaignid" column matches that of the current "campaign", would anyone have any ideas.

This is the query that displays the data:

  $counter=1;               $userID=PageDB::getInstance()->get_user_id_by_name($_SESSION['user']);              $result=PageDB::getInstance()->get_pages_by_campaign_id($campaignID);
            $i=0;
                while ($row = mysqli_fetch_array($result)):
                 $style = "";
                    if($i%2==0)
    {
        $style = ' style="background-color: #EFEFEF"';
    }
    echo "<tr".$style.">";
                echo "<td>" . htmlentities($row['pid']) . "</td>";
                echo "<td>". htmlentities($row['id']) . "</td>";
                ?>
                <td>
                <form style="display:none;"></form>
                    <form name="editPage" action="editPage.php" method="GET">
                        <input type="hidden" name="pageID" value="<?php echo $pageID = $row['pid']; ?>" />
                        <input type="submit" name="editPage"  value="<?php echo "Page "  . $counter; ?>" style="padding-top:4px; padding-bottom:6px;background:none;border:none; cursor:pointer"/>
                    </form> 
    </td>           
                <?php
                $pageID = $row['pid'];  
                $counter++;
                $i++;

                echo "</tr>
";
            endwhile;
            mysqli_free_result($result);              
?>   

And here is how I am querying the database.

public function get_pages_by_campaign_id($campaignID) {
    $campaignID = $this->real_escape_string($campaignID);
    return $this->query("SELECT pid,campaignid,id,campaign_name FROM pages,campaigns WHERE pages.campaignid = campaigns.id ORDER BY campaigns.id LIMIT 1,10");
    }

As I said it is returning the right data, but I only want to display the data where: pages.campaignid = campaigns.id [1] or pages.campaignid = campaigns.id [r] etc...

  • 写回答

1条回答 默认 最新

  • duangouyan3328 2012-05-18 12:23
    关注

    You need and additional if-else condition inside your while loop. This if-else statement will compare if current row is equal to campaigns.id

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看