Page 1 of 1

mysql_query under conditions

Posted: Wed Nov 13, 2013 3:38 am
by dexpras
I need to check the availability of rooms for a specified period for room booking website, but with the following function; if room is unavailable it out puts 101, if available outputs 000; but I want it to be just 1 or 0.

Code: Select all

function room_unavailable($room_name, $s_at, $e_at){
				
		$room_name = sanitize($room_name);
	//	$s_at = sanitize();
	//	$e_at = sanitize();
		
		$query = mysql_query("SELECT COUNT('room_name') FROM `ordered_rooms` WHERE (`s_at` BETWEEN 7 AND '$e_at') AND (`e_at` BETWEEN '$s_at' AND 18)AND `room_name`= '$room_name'");
		echo intval((mysql_result($query, 0)));

	}
Because I need to return true or false by using

Code: Select all

return (mysql_result($q, 0)== 1) ? true: false;
, Instead of

Code: Select all

echo (mysql_result($query, 0));

Re: mysql_query under conditions

Posted: Wed Nov 13, 2013 1:03 pm
by requinix
Okay... so why not do that?