gpt4 book ai didi

php - 子查询中可以使用limit吗?

转载 作者:行者123 更新时间:2023-11-29 22:09:15 25 4
gpt4 key购买 nike

我想在管理中显示评论,并且在每个页面中我显示 20 个通讯网。我想将这 20 个通信网的可见字段设置为 1。我使用此查询,但出现错误

public static function seen_comment($per_page,$offset){
global $db;
$sql =" UPDATE ".self::$table_name;
$sql.=" SET seen=1";
$sql.=" WHERE id IN ";
$sql.=" ( SELECT id FROM comment ORDER BY id DESC )";
$sql.=" LIMIT $per_page OFFSET $offset ";

$db->query($sql);
}

有什么问题吗?对于这种情况最好的方法是什么?

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OFFSET 0' at line 1' in C:\wamp\www\1hezar\inc\class\comment.php on line 89

最佳答案

你可以试试这个

<?php 
public static function seen_comment($per_page,$offset){
global $db;
$sql =" UPDATE ".self::$table_name ."
SET `seen`=1
WHERE `id`
IN ( SELECT id FROM comment ORDER BY id DESC LIMIT $per_page OFFSET $offset ) ";
$db->query($sql);
}
?>

希望有效果

关于php - 子查询中可以使用limit吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31849313/

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