PHP和MySQL内容显示不正常



在动态生成具有不同类型内容的页面时,"post"内容出现在正在生成的静态内容之上。我想换一种方式。我的代码中是否有任何东西会导致这种情况发生,或者你认为问题与我的数据库有关?谢谢

$query = "SELECT * FROM content WHERE pages LIKE '%$pageID%'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
// Display pages's static content
if ($row['type'] == "static") {
    echo "
        <h2>" . $row['tile'] . "</h2>
        <content>" . $row['body'] . "</content>
    ";
}
// Display pages's posts
else {
    echo "
        <h2>" . $row['tile'] . "</h2>
        <content>" . $row['body'] . "</content>
    ";
}
SELECT * FROM content WHERE pages LIKE '%$pageID%' ORDER BY type desc

将其添加到查询的末尾:

ORDER BY CASE WHEN type = 'static' THEN 0 ELSE 1 END

最新更新