$result = mysql_query("SELECT transaction_id FROM booking WHERE
school_id = $school AND weeknumber = $weeknumber GROUP BY
transaction_id") or die(mysql_error());
if(mysql_num_rows($result) == 0){
echo "There are no bookings.";
exit;
}
Many thanks,
Chris
>My query doesn't work on the occassion that transaction_id is null,
>which may be the case. How would I fix this?
>
>SELECT transaction_id FROM booking WHERE
>school_id = $school AND weeknumber = $weeknumber GROUP BY
>transaction_id
What do you intend to achieve with the GROUP BY clause in this case?
--
Erick
That depends, what does it mean that transaction_id is null for a
booking? You can exclude those rows via the is not null predicate, or
you can map null to some fictive transaction_id via the coalesce
function, but possibly the best solution is to fix the schema so that
the situation wont occur.
/Lennart
[...]
Please define "doesn't work". I think you will find that the query
does precisely what it is supposed to do in the circumstances, so from
that PoV it "works" just fine.
It obviously doesn't do what you want it to, so please tell us what
you are wanting. As has already been pointed out, there is no obvious
(to us) reason for the GROUP BY clause, so an explanation of what you
expect the query to achieve would be kinda useful.
By the way, since you seem to feel that it is OK to not layout your
query neatly, why not go the whole hog with your php too: