我有下表,我想选择所有(通过php查询),但只选择与course1匹配的行,我尝试了以下但是它没有工作。
$comments = array();
$result = mysql_query("select * from comments where course1='$post_id' order by id ASC");
什么是正确的查询?
+----+-----------+----------+-----+-------------------------+---------------+-------------
| id | post_id | name | url | email | body | dt |
+----+-----------+----------+-----+-------------------------+---------------+-------------
| 1 | course2 | john | | john@john.com | comments by john | 2012-11-16 |
| 2 | course1 | wiki | | wiki@wiki.com | comments by wiki | 2012-11-16 |
| 3 | course2 | daniel | | daniel@gmail.com | comments by daniel | 2012-11-16 |
| 4 | course2 | ram | | ram@ram.com | comments by ram | 2012-11-16 |
| 5 | course1 | velu | | velu@velu.com | comments by velu | 2012-11-16 |
+----+-----------+----------+-----+-------------------------+---------------+-------------
答案 0 :(得分:0)
您需要引用您正在搜索的字段名称:
$result = mysql_query("select * from comments where post_id='$post_id' order by id ASC");
$ post_id字符串变量包含值“course1”。
答案 1 :(得分:0)
试试这个:
$result = mysql_query("select * from comments where post_id='$post_id' order by id ASC");
答案 2 :(得分:0)
试试这个:SELECT * FROM comments WHERE post_id ='course1'由id ASC命令
我认为你在sql
中混淆了你的列名和搜索值