mysql_query under conditions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dexpras
Forum Newbie
Posts: 4
Joined: Mon Nov 11, 2013 6:15 am

mysql_query under conditions

Post 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));
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mysql_query under conditions

Post by requinix »

Okay... so why not do that?
Post Reply