0

我正在尝试将 mySQL 数据库表过滤到网页中。在使用查询从列中获取特定数据时,我可以:

$result = mysql_query("SELECT * FROM availability WHERE location = 'London'");

但是我遇到的特别麻烦是从有一些变量值和一些 NULL 值的列中检索结果。我只是无法让它工作。我想要做的是选择表,识别一列,然后显示该特定列的所有结果,其中有一个值,即不为空。目前我已经尝试过这样的事情:

$result = mysql_query("SELECT * FROM availability WHERE team IS NOT NULL")

$result = mysql_query("SELECT team FROM availability WHERE team IS NOT NULL");

我究竟做错了什么?我不是 PHP 专家,并且研究并尝试了各种解决方案,但我不断收到服务器错误。感激地收到任何建议。

4

2 回答 2

2

You forgot a semicolon between the first and the second row:

$result = mysql_query("SELECT * FROM availability WHERE team IS NOT NULL");
$result = mysql_query("SELECT team FROM availability WHERE team IS NOT NULL");

And I guess you don't want to name both variables as $result.

PS: You should use MySQLi or PDO instead of mysql_* functions, which are deprecated. More information avalible here.

于 2013-06-13T13:48:02.180 回答
0

你做了正确的sql。正确的sql应该是:

$result = mysql_query(" SELECT `team` FROM `availability` WHERE `team` IS NOT NULL");

然后只显示那些不为空的值。您只需检查您在 where 条件下使用了正确的字段..

于 2013-06-13T14:00:57.913 回答