Reputation: 271
i have create a database with three tables. I have a table "field" which has an id_field from 1-5 and a table name slot which has start and end times. When i want to show all the available fields and times is okay but i when i want to show the field with id value 1 is still showing all the fields!!!!!
Here is my code:
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>");
I dont know why it doesnt show me only the field with id one and is still showing me all the fields!!!!
Upvotes: 0
Views: 75
Reputation: 115630
Your query has two WHERE
clauses:
.... WHERE id_field = 1 CROSS JOIN slot WHERE ...
It should result in a database error. Proper syntax is:
SELECT *
FROM field
CROSS JOIN slot
WHERE id_field = 1
AND (id_field,id_slot)
...
Upvotes: 1