Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: available rooms

  1. #1
    New Coder
    Join Date
    Oct 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    available rooms

    function rooms ( $row, $corp_id=0 ) {
    global $s1, $s2, $s3 ;
    $Rooms = $row['Rooms'];
    $query = "SELECT SUM(1), SUM(2), SUM(3), SUM(triples), SUM(executives), SUM(RType6), SUM(RType7), SUM(RType8), SUM(RType9), SUM(RType10)
    FROM Bookingsystem WHERE start_date <= '$date' AND end_date >= '$date' AND corporate_id IS ";
    $query .= ($corp_id?"NOT NULL":"NULL");
    $res2 = mysql_query( $query )
    or die("$query<br>".mysql_error());
    $row2 = mysql_fetch_row( $res2 );
    if( $row['1'] - $row2[0] < $s1 ){ return "onebedroom"; }
    if( $row['2'] - $row2[1] < $s2){ return "twobedrooms"; }
    if( $row['3'] - $row2[2] < $s3 ){ return "apartmant"; }
    if( $row['triples'] - $row2[3] < $triples ){ return "triples"; }
    if( $row['executives'] - $row2[4] < $executives ){ return "executives"; }
    if( $row['RType6'] - $row2[5] < $RType6 ){ return "RType6"; }
    if( $row['RType7'] - $row2[6] < $RType7 ){ return "RType7"; }
    if( $row['RType8'] - $row2[7] < $RType8 ){ return "RType8"; }
    if( $row['RType9'] - $row2[8] < $RType9 ){ return "RType9"; }
    if( $row['RType10'] - $row2[9] < $RType10 ){ return "RType10"; }

    return 0;
    }

    function check_date_interval( $startDate, $endDate, $is_corp=0 ) {
    $query = "SELECT * FROM bookingsystem WHERE date >= $start_date AND date <= $end_date AND is_corporate=$is_corp";
    $res = mysql_query( $query )
    or die("$query<br>".mysql_error());
    while( $row = mysql_fetch_array( $res ) ) {
    if( $ret = check_date( $row, $is_corp ) ) return $ret;
    }
    return 0;
    }

    function get_special_summ( $startDate, $endDate, $spec_id, $s1, $s2, $s3, $triple, $executive, $RType6, $RType7, $RType8 , $RType9, $RType10, $exec_guest_number) {
    $res=mysql_query("SELECT bookigsystem FROM Rooms");
    $i=1;
    while( $row = mysql_fetch_array( $res ) )
    {
    $rooms[$i]=$row['rooms'];
    $i++;
    }
    $query2 = "SELECT MAX(date) AS max, MIN(date) AS min FROM Rooms WHERE special_desc_id=$spec_id";
    $res2 = mysql_query( $query2 ) or die( "$query2<br>".mysql_error());
    $row2 = mysql_fetch_array( $res2 );
    $query = "SELECT * FROM bookingsystem,Specials WHERE Rooms.special_desc_id = Specials.special_id AND Rooms.special_desc_id=$spec_id";
    $res = mysql_query( $query ) or die( "$query<br>".mysql_error());
    $row = mysql_fetch_array( $res );
    $length = $row['length'];
    $d=mktime();
    $d=date("Y-m-d",$d);
    if ($startDate<$d) return -1;
    $summ = 1 * $row['1']*$Rooms[1] +
    2 * $row['2'] * $Rooms[3]+ 3 * $row['3'] * $Rooms[1] + $triples * $row['triples'] * $adult[4]+
    $executives * $row['executives'] * $exec_guest_number+ $RType6*$row['RType6']*$adult[6]+$RType7*$row['RType7']*$adult[7]+
    $RType8*$row['RType8']*$adult[8]+$RType9*$row['RType9']*$adult[9]+$RType10*$row['RType10']*$adult[10];

    return $summ;
    }

    function get_summ( $startDate, $endDate, $s1, $s2, $s3, $triples, $executives, $RType6, $RType7, $RType8 , $RType9, $RType10, $exec_guest_number, $corp_id = 0 ) {
    $res=mysql_query("SELECT bookingsystem FROM Rooms");
    $i=1;
    while( $row = mysql_fetch_array( $res ) )
    {
    $rooms[$i]=$row['rooms'];
    $i++;
    }
    $query = "SELECT (TO_DAYS($end_date) - TO_DAYS($start_date)) AS Q";
    $res2 = mysql_query( $query ) or die( "$query<br>".mysql_error());
    $row2 = mysql_fetch_array( $res2 );
    $days_need = $row2['Q'];
    $query = "SELECT * FROM Rooms WHERE special_desc_id = 0 AND date >= $start_date AND date < $end_date AND corporate_id=$corp_id";
    $res = mysql_query( $query )
    or die( "$query<br>".mysql_error());
    while( $row = mysql_fetch_array( $res ) ) {
    $summ += 1 * $row['1']*$Rooms[1] +
    2 * $row['2'] * $Rooms[2]+3 * $row['3'] * $Rooms[3] + $s1 * $row['1'] * $Rooms[$s1]+
    $s2 * $row['$s2'] * 2+ $RType6*$row['2']*$Rooms[3]+$RType7*$row['RType7']*$Rooms[7]+
    $RType8*$row['RType8']*$adult[8]+$RType9*$row['RType9']*$adult[9]+$RType10*$row['RType10']*$adult[10];
    $days++;
    }
    if( $days != $days_need ){ return -1; }
    return $summ;
    }

    ?>

  • #2
    New Coder
    Join Date
    Oct 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    available rooms

    function rooms ( $row, $corp_id=0 ) {
    global $s1, $s2, $s3 ;
    $Rooms = $row['Rooms'];
    $query = "SELECT SUM(1), SUM(2), SUM(3), SUM(triples), SUM(executives), SUM(RType6), SUM(RType7), SUM(RType8), SUM(RType9), SUM(RType10)
    FROM Bookingsystem WHERE start_date <= '$date' AND end_date >= '$date' AND corporate_id IS ";
    $query .= ($corp_id?"NOT NULL":"NULL");
    $res2 = mysql_query( $query )
    or die("$query<br>".mysql_error());
    $row2 = mysql_fetch_row( $res2 );
    if( $row['1'] - $row2[0] < $s1 ){ return "onebedroom"; }
    if( $row['2'] - $row2[1] < $s2){ return "twobedrooms"; }
    if( $row['3'] - $row2[2] < $s3 ){ return "apartmant"; }
    if( $row['triples'] - $row2[3] < $triples ){ return "triples"; }
    if( $row['executives'] - $row2[4] < $executives ){ return "executives"; }
    if( $row['RType6'] - $row2[5] < $RType6 ){ return "RType6"; }
    if( $row['RType7'] - $row2[6] < $RType7 ){ return "RType7"; }
    if( $row['RType8'] - $row2[7] < $RType8 ){ return "RType8"; }
    if( $row['RType9'] - $row2[8] < $RType9 ){ return "RType9"; }
    if( $row['RType10'] - $row2[9] < $RType10 ){ return "RType10"; }

    return 0;
    }

    function check_date_interval( $startDate, $endDate, $is_corp=0 ) {
    $query = "SELECT * FROM bookingsystem WHERE date >= $start_date AND date <= $end_date AND is_corporate=$is_corp";
    $res = mysql_query( $query )
    or die("$query<br>".mysql_error());
    while( $row = mysql_fetch_array( $res ) ) {
    if( $ret = check_date( $row, $is_corp ) ) return $ret;
    }
    return 0;
    }

    function get_special_summ( $startDate, $endDate, $spec_id, $s1, $s2, $s3, $triple, $executive, $RType6, $RType7, $RType8 , $RType9, $RType10, $exec_guest_number) {
    $res=mysql_query("SELECT bookigsystem FROM Rooms");
    $i=1;
    while( $row = mysql_fetch_array( $res ) )
    {
    $rooms[$i]=$row['rooms'];
    $i++;
    }
    $query2 = "SELECT MAX(date) AS max, MIN(date) AS min FROM Rooms WHERE special_desc_id=$spec_id";
    $res2 = mysql_query( $query2 ) or die( "$query2<br>".mysql_error());
    $row2 = mysql_fetch_array( $res2 );
    $query = "SELECT * FROM bookingsystem,Specials WHERE Rooms.special_desc_id = Specials.special_id AND Rooms.special_desc_id=$spec_id";
    $res = mysql_query( $query ) or die( "$query<br>".mysql_error());
    $row = mysql_fetch_array( $res );
    $length = $row['length'];
    $d=mktime();
    $d=date("Y-m-d",$d);
    if ($startDate<$d) return -1;
    $summ = 1 * $row['1']*$Rooms[1] +
    2 * $row['2'] * $Rooms[3]+ 3 * $row['3'] * $Rooms[1] + $triples * $row['triples'] * $adult[4]+
    $executives * $row['executives'] * $exec_guest_number+ $RType6*$row['RType6']*$adult[6]+$RType7*$row['RType7']*$adult[7]+
    $RType8*$row['RType8']*$adult[8]+$RType9*$row['RType9']*$adult[9]+$RType10*$row['RType10']*$adult[10];

    return $summ;
    }

    function get_summ( $startDate, $endDate, $s1, $s2, $s3, $triples, $executives, $RType6, $RType7, $RType8 , $RType9, $RType10, $exec_guest_number, $corp_id = 0 ) {
    $res=mysql_query("SELECT bookingsystem FROM Rooms");
    $i=1;
    while( $row = mysql_fetch_array( $res ) )
    {
    $rooms[$i]=$row['rooms'];
    $i++;
    }
    $query = "SELECT (TO_DAYS($end_date) - TO_DAYS($start_date)) AS Q";
    $res2 = mysql_query( $query ) or die( "$query<br>".mysql_error());
    $row2 = mysql_fetch_array( $res2 );
    $days_need = $row2['Q'];
    $query = "SELECT * FROM Rooms WHERE special_desc_id = 0 AND date >= $start_date AND date < $end_date AND corporate_id=$corp_id";
    $res = mysql_query( $query )
    or die( "$query<br>".mysql_error());
    while( $row = mysql_fetch_array( $res ) ) {
    $summ += 1 * $row['1']*$Rooms[1] +
    2 * $row['2'] * $Rooms[2]+3 * $row['3'] * $Rooms[3] + $s1 * $row['1'] * $Rooms[$s1]+
    $s2 * $row['$s2'] * 2+ $RType6*$row['2']*$Rooms[3]+$RType7*$row['RType7']*$Rooms[7]+
    $RType8*$row['RType8']*$adult[8]+$RType9*$row['RType9']*$adult[9]+$RType10*$row['RType10']*$adult[10];
    $days++;
    }
    if( $days != $days_need ){ return -1; }
    return $summ;
    }

    ?>




    I have this code i am trying to make limit of the 30 rooms in one range of the time.So I have 10 rooms of the one bedroom(Number 1),10 two bedrooms(number 2) and 10 apartmants(number 3) .So in my datebase if someone wants to book number 1 room massege has to come up is said all rooms occupied.So is not possibly to 11 customer of the room number 1 to book room is same range like anothers 10.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    So not only did you post that slop twice, you also ignored the sticky topics about [php] tags too?

    You won't get much help here like that..
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #4
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    It appears he forgot to ask his question the first time.

  • #5
    New Coder
    Join Date
    Oct 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Rooms available

    Please help i have been working on this project already 3 months.What i have to change in above code to get this code working






    In my field for rooms to reserve room if you enter number 1 that's mean one bedroom,number 2 mean two beds,number 3 mean apartment.So if one customer want reserve 8/30/2013 by 8/31/2013 and it is 111 customer ,i need message coming out all rooms number 1 occupied please choose another room.By the way all those numbers they are record in datebase(php admin).

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    And what is the problem you're actually having? You'll need to do better than dropping all of these functions here and saying something isn't working.

    Given the queries you have here, you appear to have some pretty substantial normalization issues. What I should be able to do is SELECT count(id) FROM Reservation WHERE roomType = 'SINGLE' for example. Instead, you need to query *every* record within the BookingSystem, and then compare to see if its full. Each record themselves dictate what type it is, and only from a rigid structure model, so that makes this non-scalable.
    Another thing to note, sum of 4 is still four. Sum of 4 * number of records <> sum of `4`. Integers shouldn't be used for properties, just like reserved words shouldn't be. So you'll need to query sum(`4`) if you stick with this structure (which you shouldn't).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    New Coder
    Join Date
    Oct 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Rooms available

    SELECT count(id) FROM Reservation WHERE roomType = 'SINGLE' that goes in Sql but i always had problem with that and never have working.I need some simple php code which will work.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Umm, what? I'm saying your normalization is broke. You need to go back to the design phase to fix it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #9
    Regular Coder
    Join Date
    Aug 2013
    Posts
    130
    Thanks
    5
    Thanked 0 Times in 0 Posts

    rooms available

    PHP Code:
    <?php

    function room_available($roomid,$date){ // date in format YYYY-MM-DD

    /* ([PHP][PHP][PHP]
    [/PHP][/PHP]
    03
    You can use this snippet when you leave this copyright message here. */

    $sql = "SELECT * FROM rooms WHERE RoomID = \'".$roomid."\' AND startdate <= \'".$date."\' AND EndDate >= \'".$date."\'"; //making sql

    $res= mysqli_query($link,$sql);//executes the query

    if(mysqli_num_rows($res)>0){

    return 'occupied';

    } else {

    return 'empty';

    }



    }


    ?>

    [/PHP]



    I have this code too but is not working.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •