gpt4 book ai didi

sql - mysql_num_rows 错误

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

不知道问题出在哪里!

$msgs = mysql_num_rows(mysql_query("SELECT * FROM messages WHERE recipient = $userID AND read = 0"));


echo $msgs;

如果我删除“and read =0”,上面的代码就可以工作。但如果不是我得到:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in left_menu.php on line 16
.

I have a field in the table called read (tinyint 1,defualt 0)

CREATE TABLE IF NOT EXISTS `messages` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`sender` int(10) unsigned NOT NULL DEFAULT '0',
`recipient` int(10) unsigned NOT NULL DEFAULT '0',
`subject` varchar(255) CHARACTER SET utf8 NOT NULL,
`message` text CHARACTER SET utf8,
`date` int(10) unsigned NOT NULL DEFAULT '0',
`read` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)

INSERT INTO `messages` (`id`, `sender`, `recipient`, `subject`, `message`, `date`, `read`) VALUES
(1, 47, 13, 'Hello!', 'TEST!', 1228326055, 0),
(2, 536, 13, 'blblabla', 'yeah', 1248506708, 0);

有什么问题吗?

最佳答案

read 是保留关键字,因此这会生成 MySQL 语法错误。但是,在 MySQL 提示符下,这是有效的:

SELECT * FROM messages WHERE recipient = 1 AND `read` = 0;

您必须在 PHP 查询中对其进行反引号。

关于sql - mysql_num_rows 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1182016/

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