Hi,
First of all, in the FROM clause you have 'hotel.bookings'. Is that correct ... database called 'hotel', table called 'bookings'?
Secondly, is the field 'RoomID' numeric or char-based (VARCHAR or whatever). If it's numeric, get rid of the single-quotes around the 1 in the WHERE clause.
Anyway, give the calculated field an alias (using the AS keyword). Then refer to that in the PHP ...
<?php
mysql_connect("localhost", "root", "password");
$result = mysql_query("
SELECT COUNT(*) AS `bookings_count`
FROM hotel.bookings
WHERE RoomID = '1'
AND DateCheckin <= '06/01/2005'
AND DateCheckout >= '06/03/2005'
") or die (mysql_error());
while ($row = mysql_fetch_array($result)){
echo '<input name="result" value="'.$row['bookings_count'].'">';
if(0 < $row['bookings_count']){
echo "greater than zero";
} else {
echo "less than (or equal to) zero";
}
}
?>
Paul 🙂
PS. I couldn't resist tweaking your code ...
Use single-quoted strings rather than double-quoted, especially for HTML (loads of books, tutorials use double-quoted strings, but they are often just lazy in their explanation of why.)
Spread your code out at bit ... especially when you are learning ... just makes life easier when it comes to debugging etc.