Fix the code

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

marijan_9
Forum Newbie
Posts: 8
Joined: Wed Apr 22, 2015 8:30 pm

Fix the code

Post 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 />";

}

}

}
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Fix the code

Post by Celauran »

Not working how?
marijan_9
Forum Newbie
Posts: 8
Joined: Wed Apr 22, 2015 8:30 pm

Re: Fix the code

Post 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
marijan_9
Forum Newbie
Posts: 8
Joined: Wed Apr 22, 2015 8:30 pm

Re: Fix the code

Post by marijan_9 »

Any help
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Fix the code

Post 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 "
(#10850)
marijan_9
Forum Newbie
Posts: 8
Joined: Wed Apr 22, 2015 8:30 pm

Re: Fix the code

Post by marijan_9 »

http://alooot.com/datebase/image.html
data in the rows returned by the query look like this
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Fix the code

Post 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.
(#10850)
marijan_9
Forum Newbie
Posts: 8
Joined: Wed Apr 22, 2015 8:30 pm

Re: Fix the code

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Fix the code

Post by Christopher »

Something is wrong with your formatting. I can't follow what you are saying. Perhaps one step at a time?
(#10850)
marijan_9
Forum Newbie
Posts: 8
Joined: Wed Apr 22, 2015 8:30 pm

Re: Fix the code

Post by marijan_9 »

set up maxrooms1,maxrooms2 and maxrooms3 on this query or limits maxrooms1=20,maxrooms2=30 and maxrooms3=30;
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Fix the code

Post 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.
(#10850)
marijan_9
Forum Newbie
Posts: 8
Joined: Wed Apr 22, 2015 8:30 pm

Re: Fix the code

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Fix the code

Post by Christopher »

No, sorry, it is not clear to me. Can you show what all data looks like?
(#10850)
marijan_9
Forum Newbie
Posts: 8
Joined: Wed Apr 22, 2015 8:30 pm

Re: Fix the code

Post by marijan_9 »

Do you have skype so we can talk and make clear for you.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Fix the code

Post by Christopher »

We only allow posting via these forums. You need to describe the problem clearly and provide what is asked for.
(#10850)
Post Reply