我创建了一个包含三个表的数据库。我有一个表“字段”,其中包含1-5的id_field和一个具有开始和结束时间的表名称槽。当我想显示所有可用的字段和时间是可以的,但当我想显示id值为1的字段仍然显示所有字段!!!!!
这是我的代码:
echo("<select name='selSlot'>");
$mysql_link = mysql_connect("localhost","root","*********");
$db_select = mysql_select_db("nuevo", $mysql_link);
$query = "SELECT * FROM field WHERE id_field = 1 CROSS JOIN slot WHERE (id_field,id_slot) ".
"NOT IN(Select field_slot,res_slot From reservation WHERE res_date = '"
.$today['year']."-".$today['mon']."-".$today['mday']."') ORDER by id_field,id_slot";
$result = mysql_query($query)
or die ("Query '$query' failed with error message: " . mysql_error ());
$row = mysql_fetch_assoc($result);
echo "apoel";
while ($row) {
echo("<option value='" .$row['id_field'].",".$row['id_slot']."'>".$row['description'].
" ".$row['start_time']."-".$row['end_time']." </option>");
$row = mysql_fetch_assoc($result);
}
echo("</select>");
我不知道为什么它不会只显示id为1的字段而且仍然向我显示所有字段!!!!
答案 0 :(得分:1)
您的查询有两个WHERE
子句:
.... WHERE id_field = 1 CROSS JOIN slot WHERE ...
它应该导致数据库错误。正确的语法是:
SELECT *
FROM field
CROSS JOIN slot
WHERE id_field = 1
AND (id_field,id_slot)
...