Page 1 of 2

Fix the code

Posted: Wed Apr 22, 2015 8:34 pm
by marijan_9
this code is not working anyone can fix it

Code: Select all

$maxRooms1 =6;
$maxRooms2 =5;
$maxRooms3 = 5;




$fetchQuery = "SELECT datefrom, rooms, COUNT( datefrom ) , COUNT( rooms ) 
FROM calendar3
GROUP BY rooms, datefrom ";



$fetchResult = mysql_query($fetchQuery);
$numberRooms = mysql_num_rows($fetchResult);



if ($numberRooms >= $maxRooms1) {
echo "</br>"."The beds are not available!!";
} elseif ($numberRooms < $maxRooms1) {
echo "</br>"."1 The beds are available! !";

}
if ($numberRooms >= $maxRooms2) {
echo "</br>". "rooms two beds are not available!!";
} elseif ($numberRooms < $maxRooms2) {
echo "</br>". "2 ima !";

} 

if ($numberRooms >= $maxRooms3) {
echo "</br>". "3 not available!";
} elseif ($numberRooms < $maxRooms3) {
echo "</br>". "3 rooms beds are available! !";

} 





$maxRooms1 =6;
$maxRooms2 =5;
$maxRooms3 = 5;


$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result))
{
if($row['COUNT(datefrom)'] <= $maxRooms1){


echo '<font color="#FF4040">'."<br />"."Date ".$row['datefrom']." for one bed is not available". "<br />"."Select another date or room." ; 
}
elseif ($row['COUNT(datefrom)'] >$maxRooms1) {
echo '<font color="#00CC00">'."The rooms one beds are available!"."<br />";

"<br />";

}

}

if($row['COUNT(datefrom)'] <= $maxRooms2){


echo '<font color="#FF4040">'."<br />"."Date ".$row['datefrom']." for two beds is not available". "<br />"."Select another date or room." ; 
}
elseif ($row['COUNT(datefrom)'] > $maxRooms2){ {
echo "</br>".'<font color="#00CC00">'."The rooms two beds are available!"."<br />";

"<br />";

}


if($row['COUNT(datefrom)'] <= $maxRooms3){


echo '<font color="#FF4040">'."<br />"."Date ".$row['datefrom']." for three beds is not available". "<br />"."Select another date or room." ; 
}
elseif ($row['COUNT(datefrom)'] > $maxRooms3){ {
echo '<font color="#00CC00">'."The rooms three beds are available!"."<br />";

"<br />";

}

}

}

Re: Fix the code

Posted: Wed Apr 22, 2015 9:21 pm
by Celauran
Not working how?

Re: Fix the code

Posted: Wed Apr 22, 2015 9:40 pm
by marijan_9
http://alooot.com/vjezba1%20-%20Copy%20[2].php


1 bed is available !
2 two beds is available !
3 three beds is not available !



Date 2015-12-12 for one bed is not available>>>>>>>>>>>>>this is different then up there
Select another date or room.
Date 2015-12-12 for one bed is not available
Select another date or room.
Date 2015-12-12 for one bed is not available
Select another date or room.
Date 2015-12-13 for one bed is not available
Select another date or room.
Date for two beds is not available
Select another date or room.


You see on the page diffrence should be same

Re: Fix the code

Posted: Thu Apr 23, 2015 9:55 am
by marijan_9
Any help

Re: Fix the code

Posted: Sat Apr 25, 2015 4:12 pm
by Christopher
Can you show us what the data in the rows returned by the query look like?

Also, you might want to alias your COUNT() with names to use in the code, like: " COUNT(datefrom) AS num_dates, COUNT(rooms) AS num_rooms "

Re: Fix the code

Posted: Mon Apr 27, 2015 11:39 am
by marijan_9
http://alooot.com/datebase/image.html
data in the rows returned by the query look like this

Re: Fix the code

Posted: Mon Apr 27, 2015 2:57 pm
by Christopher
Now that I look at it, I am more confused than before. For example, in your query the values returned for COUNT(datefrom) and COUNT(rooms) will always be the same. And I don't see how you can determine how many one, two and three bed rooms are available from this data? it seem like in addition to datefrom you also need to group by the number of beds in each room.

Re: Fix the code

Posted: Tue Apr 28, 2015 8:16 am
by marijan_9
group by the number of beds in each room forget about that what i need SELECT datefrom, rooms, COUNT( datefrom ) , COUNT( rooms )
FROM calendar3
GROUP BY rooms, datefrom and set up maxrooms1,maxrooms2 and maxrooms3 on this query or limits maxrooms1=20,maxrooms2=30 and maxrooms3=30; then
if ($numberRooms >= $maxRooms1 and $datefrom >=$maxRooms1) {>>>>>>>>>>>but here need to make that is in same row datefrom >>>>>>>>>>>.and rooms1

also same row datefrom >>>>>>>>>>>..........................................................................................................................................and rooms2

same row datefrom >>>>>>>>>>>..........................................................................................................................................and rooms3















echo "</br>"."The beds are not available!!";
} elseif ($numberRooms < $maxRooms and $datefrom <$maxRooms1) {
echo "</br>"."1 The beds are available! !";


COUNT(datefrom) and COUNT(rooms) won't be same alwaays

Re: Fix the code

Posted: Tue Apr 28, 2015 5:54 pm
by Christopher
Something is wrong with your formatting. I can't follow what you are saying. Perhaps one step at a time?

Re: Fix the code

Posted: Wed Apr 29, 2015 1:17 pm
by marijan_9
set up maxrooms1,maxrooms2 and maxrooms3 on this query or limits maxrooms1=20,maxrooms2=30 and maxrooms3=30;

Re: Fix the code

Posted: Wed Apr 29, 2015 4:25 pm
by Christopher
Is that what you want to do? Are maxrooms1,maxrooms2 and maxrooms3 fields in the database?

You showed the query results, but did not show example data from the database.

Re: Fix the code

Posted: Mon May 04, 2015 4:58 pm
by marijan_9
http://alooot.com/datebase/image.html

i need to say in code if count(datefrom)and count(rooms) in rooms 1 (row where is said 1) >8 no more rooms
also need to say in code if count(datefrom)and count(rooms) in rooms 2 (row where is said 2)>12 no more rooms
also need to say in code if count(datefrom)and count(rooms) in rooms 3 (row where is said 3) >15 no more rooms
I think should be clear now for you.

Re: Fix the code

Posted: Tue May 05, 2015 10:50 pm
by Christopher
No, sorry, it is not clear to me. Can you show what all data looks like?

Re: Fix the code

Posted: Fri May 08, 2015 9:50 am
by marijan_9
Do you have skype so we can talk and make clear for you.

Re: Fix the code

Posted: Fri May 08, 2015 11:03 pm
by Christopher
We only allow posting via these forums. You need to describe the problem clearly and provide what is asked for.