使用php mysql标记系统

时间:2013-06-18 19:56:20

标签: php mysql tagging

我在这里有一些代码,我不明白如何使这项工作:

$query = "SELECT * FROM `blog-posts` ORDER BY `date` DESC LIMIT 0, 10 WHERE `tags` LIKE '%test%'";
$result = mysql_query($query);

while($posts = mysql_fetch_array($result)) {
    echo $posts["title"] . "<br>";
    echo $posts["text"] . "<br>";
    $mydate = strtotime($posts["date"]);
    echo date('j M', $mydate) . "<br>";
    echo $posts["tags"] . "<br>";
    }
    echo "<a style=\"float:right;\" href=\"logout.php?action=logout\">Log out</a>";

有人可以帮助我吗? GRTS。

2 个答案:

答案 0 :(得分:1)

您的查询中的参数顺序错误。 WHERE需要在ORDER BYLIMIT之前完成。

$query = "SELECT * FROM `blog-posts` WHERE `tags` LIKE '%test%' ORDER BY `date` DESC LIMIT 0, 10";

答案 1 :(得分:0)

您的MySQL查询中的子句顺序错误,WHERE应该位于ORDER BYLIMIT之前。

$query = "SELECT * FROM `blog-posts` WHERE `tags` LIKE '%test%' ORDER BY `date` DESC LIMIT 0, 10 ";

除此之外,你的问题中没有足够的信息可以找出任何东西。