How echo $num ,find overlapCount of the rooms

$hostname_ = "";
$database_ = "";
$username_ = "";
$password_ = "";
$= mysql_pconnect($hostname_ $username_, $password_) or trigger_error(mysql_error(),E_USER_ERROR); 
echo  $num;
function overlapCount($num) { // This is used later when echo'ing the room listing 
  if(in_array($num,array(1,2,3))) { 
    switch ($num % 10) { 
      case 1: return $num.'st'; 
      case 2: return $num.'nd'; 
      case 3: return $num.'rd'; 
    } 
  } 
  return $num.'th'; 
}

$num()

I see your add suffix code but what does this have to do with “overlapCount of the rooms”?
OR is your suffix code not working as expected?

BTW, this is what I have on a copy I use if it makes any difference.

if (!in_array(($num % 100),array(11,12,13))){

it is mean if i have 3 three beds and 4th customers want reserve it should say no more rooms

Well I would think you would be dealing with two things. How many rooms you have and how many are booked. Some simple comparison should do the job.

$number_of_rooms=3;
$booked_rooms=2;
$rooms_left = ($booked_rooms === $number_of_rooms ? "No Rooms Left" : "Rooms Left: ".($number_of_rooms - $booked_rooms));    
echo $rooms_left;
``

$hostname_ = “”;
$database_ = “”;
$username_ = “”;
$password_ = “”;
$= mysql_pconnect($hostname_ $username_, $password_) or trigger_error(mysql_error(),E_USER_ERR

$number_of_rooms=3;
$booked_rooms=2;
$rooms_left = ($booked_rooms === $number_of_rooms ? “No Rooms Left” : "Rooms Left: ".($number_of_rooms - $booked_rooms));
echo $rooms_left

how if i have diffrent kind of the rooms one beds 3,two beds 5 and three beds 6

by the way i am getting error

How are you making query for room/bed count?
Also, regardless of “beds in the room” I would still think you would be dealing with “Rooms Booked”… that is unless you expect guests to share rooms.

Just List or Show your customers rooms based on the number of beds so they can book the kind of room they want.

The error is probably coming from $=

As mysql connection is obsolete, I would suggest using PDO for DB connection and queries.

jj

Well instead of attempting to convert code someone else wrote that you don’t understand, you should take things in baby steps by learning the best way to store the needed data (DB tables used). Then learn basic queries and move on to how you are going to display the data. Once you get a grasp of what you are doing, more advanced concepts can be added. It’s like you want to edit a finished book you’ve never read or didn’t write. Start at the beginning. The folks here as Sitepoint would be happy to help with specific questions if you get stuck.

I was making it but in parts i made from 6 parts of the code.I was taking piece of the code from many places and 80 % for me is understandable 20% not.It was looked different when i was taking the piece of the code.
right now i have output like this

You chose “3-bed” and they are in hotel 3.

Room: 3

Rooms available.

How to get output

You chose “3-bed” and they are in hotel 3.

Room: 3

Rooms available.

Room: 2

Rooms available or No more rooms available

Room: 1

Rooms available or No more rooms available

Hmmm, I would think output would be more like this… Just a guess.

//
//
// Now build our page (I commented out the example items)
//
//

    echo 'You chose "' . $bedCount . '-bed" and ' . (count($result) > 1 ? "they are" : "it is") . ' in hotel ' . $brsoba . ".\n";
    
    echo "<br />\nRoom: " . $bedCount . "<br />\n"; 
    
    foreach($arrayCount as $date => $count){ 
    
        echo  "<br />" . $date . " Has " . ($count <= 3 ? $count . "  Rooms available.<br />\n" : "  No more rooms available.<br />\n"); 
    
    }

Which would show number of available rooms by date.

You chose "2-bed" and they are in hotel 4.


Room: 2


2015-05-01 Has 2  Rooms available.


2015-05-02 Has 2  Rooms available.


2015-05-03 Has 1  Rooms available.

Room: 2 ================it is output
Has 2

Rooms available.

I was doing this before year ago and server connection is down right know i can’t check where i have to set up numbers of the rooms for each kind.Right now i have all the time Rooms available doesn’t matter how many in datebase is occupied .

You never really have said what rooms field represents or the table rooms for that matter. Rooms booked? Rooms occupied? Either way, it’s hard to know what “Available” means with relation to a single field. From our perspective it is very had to know what’s going on or intended to happen. Are there different inns involved?

You are also using the value of rooms in your switch to identify the hotel, so what does that field represent?

As far as I can tell you are getting the value of rooms for the last record. This in itself seems flawed.
Then getting dates from rooms with the same rooms value and building a dates array. If there are several records with the same room value and dates are the same, you will be getting a count for that date when you reduce and count values. Then using these counts to display what is available. Sound about right?

thanks

One more example but this is little be strange don’t be confused

$query = "select datefrom,  rooms, COUNT(datefrom) FROM calendar3 group by datefrom,  rooms order by datefrom, rooms"; 
  
  
$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result))
{
 if($row['COUNT(datefrom)'] > 2 ){
 echo '<font color="#FF4040">'."<br />"."Date ".$row['datefrom']." for this type of rooms is not available". "<br />"."Select another date or room."  ; 
 }
  elseif ($row['COUNT(datefrom)'] <= 2 ) {
    echo '<font color="#00CC00">'."The rooms are available!"."<br />";
this what i have by now
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
This is what to need to be add
So in datebase in row rooms(1)some dates are bigger then maxroooms1
maxroooms1=9;
maxroooms2=2;
 maxroooms3=1;
datefroom is row in datebase in that row is all dates (datefrom-dateto and dates between them)now i need 

on place 2 (  COUNT(datefrom)'] <= 2     )need to put $maxrooms(rooms)
i will have 

mean one bed <<<<<<<<<maxroooms1=9;
mean two  beds <<<<<<<<<maxroooms2=2;
mean three  beds,<<<<<<<<<<maxroooms3=4;



so if $row['COUNT(datefrom)'] =>$maxrooms1        rooms is not available


elseif ($row['COUNT(datefrom)'] < $maxrooms1  ) {
    echo '<font color="#00CC00">'."The rooms are available!"."<br />";

if $row['COUNT(datefrom)'] =>$maxrooms2        rooms is not available


elseif ($row['COUNT(datefrom)'] < $maxrooms2  ) {
    echo '<font color="#00CC00">'."The rooms are available!"."<br />";



if $row['COUNT(datefrom)'] =>$maxrooms3        rooms is not available


elseif ($row['COUNT(datefrom)'] < $maxrooms3  ) {
    echo '<font color="#00CC00">'."The rooms are available!"."<br />";

Again, it’s hard to follow the logic of what you would like to show. I would suggest converting the code to mysqli and build your IF ELSE conditions and see how you do. If specific questions arise, ask.

@jam_9 one of the main reasons you need to migrate away from the old mysql_* extension over to either the mysqli_* extension or PDO is that the old mysql_* extension was deprecated in version 5.5 and is being removed from the next version of PHP (PHP 7).

The other reason is that both the newer mysqli_* and extension have available the use of prepared statements which eliminate the risk of SQL injection attacks.

When dealing with user submitted data, you need to validate it to make sure it’s of the type that your expecting, withing a range of values that you’re expecting, etc

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.