无法在 mysql Select 中使用变量
$select = " SELECT * FROM comments WHERE type=$row->title; ORDER BY id desc" .
" LIMIT $low, $PerPage";
$final = mysql_query($select) or die('Error!');
$行->标题;是之前创建的,并且具有类似 Type1、Type2 或其他值的值。当我启动该脚本时,结果是“错误!”。你能告诉我为什么吗?我尝试了很多方法来解决这个问题,但没有任何结果。这是其中之一:
$mytype=$row->title;
$select = " SELECT * FROM comments WHERE type=$mytype; ORDER BY id desc" .
" LIMIT $low, $PerPage";
$final = mysql_query($select) or die('Error!');
$select = " SELECT * FROM comments WHERE type=$row->title; ORDER BY id desc" .
" LIMIT $low, $PerPage";
$final = mysql_query($select) or die('Error!');
$row->title; is previously created and it have value like Type1, Type2 or something else. When I start that script the result is "Error!". Could you tell me why? I have tried many ways to reslove the problem but without any result. This is one of them:
$mytype=$row->title;
$select = " SELECT * FROM comments WHERE type=$mytype; ORDER BY id desc" .
" LIMIT $low, $PerPage";
$final = mysql_query($select) or die('Error!');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除 ;在 $row-title 之后即:
Remove the ; after the $row-title i.e.:
你应该回显 mysql_error() - MySQL 会告诉你出了什么问题!
dqhendricks 和 Cybernate 的答案是正确的 - 您应该将字符串括在单引号中。
但是 - 您还应该转义您的文本,否则您最终会收到更多错误:
You should echo out mysql_error() - MySQL will tell you what went wrong!
The answers by dqhendricks and Cybernate are correct - you should enclose your strings in single quotes.
However - you should also be escaping your text, or you will get more errors eventually: