1

我正在尝试使用 2 个单独的表从我的数据库中获取记录。查询是

public function get_pages_by_campign_id($campaignID) {
    $campaignID = $this->real_escape_string($campaignID);
    return $this->query("SELECT pid, campaignid FROM pages,campaigns WHERE 'pages.campaignid = campaigns.id'");
}

这被调用:

$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 style='width:140px;'> Page "  . $counter .  "</td>";
                echo "<td>&nbsp;</td>";
                echo "<td></td>";


                //The loop is left open
                ?>
                <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="Edit"/>
                    </form>
                </td>
                <td>
                    <form name="deletePage" action="deletePage.php" method="POST">
                        <input type="hidden" name="pageID" value="<?php echo $pageID = $row['pid']?>"/>
                        <input type="submit" name="deletePage" value="Delete" onclick = "javascript: return confirm('Delete Page <?php echo $counter ?> ?');"/>
                    </form>
                </td>
                <?php
                $pageID = $row['pid'];  
                $counter++;
                $i++;

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

这应该列出所有“页面”记录,但它没有返回任何内容。

我已经在表“campaigns”中设置了“id”列,以使用外键与表“pages”中的“campaignid”相对应。

我设法用这个来修复它:

public function get_pages_by_campaign_id($campaignID) {
    $campaignID = $this->real_escape_string($campaignID);
    return $this->query("SELECT pid, campaignid FROM pages WHERE campaignid = 'campaigns.id'");
}
4

1 回答 1

0
"SELECT pid, campaignid FROM pages,campaigns WHERE pages.campaignid = campaigns.id"

?

于 2012-05-17T00:12:36.697 回答