gpt4 book ai didi

php - SQL 语句不会限制。显示没有结果

转载 作者:太空宇宙 更新时间:2023-11-03 12:23:19 25 4
gpt4 key购买 nike

我正在创建一个网络应用程序,我正在尝试限制结果的数量。当我进行查询时,所有结果都会返回,但如果我在语句末尾放置 LIMIT 5,则不会结果回来了。这是我的代码:

$query = $conn->prepare('SELECT * FROM notifications WHERE (needs=:username OR worker=:username) ORDER BY CASE WHEN needs=:username THEN needsread ELSE workerread END, time DESC LIMIT 5');

$query->bindParam(':username', $username);
$query->execute();

echo "<div id='notes_title' style='background-color: #333333; padding: 10px; text-align: center; font-weight: lighter; letter-spacing: 1px;'>Notes</div>";
$te = 0;
while ($rows = $query->fetch()) {

$needs = $rows['needs'];
$id = $rows['ID'];
$worker = $rows['worker'];
$title = $rows['title'];
$needsread = $rows['needsread'];
$workerread = $rows['workerread'];
$time = $rows['time'];
$type = $rows['type'];

关于为什么它不起作用的任何线索?

最佳答案

$query = $conn->prepare('SELECT * FROM notifications WHERE (needs=:username OR worker=:username) ORDER BY CASE WHEN needs=:username THEN needsread ELSE workerread END, time DESC LIMIT 5");

您的代码中存在错误。您的查询字符串以单引号开头,以双引号结尾。您的实际查询字符串是:

'SELECT * FROM notifications WHERE (needs=:username OR worker=:username) ORDER BY CASE WHEN needs=:username THEN needsread ELSE workerread END, time DESC LIMIT 5"); $query->bindParam( '

关于php - SQL 语句不会限制。显示没有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18773974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com