简体   繁体   中英

How can I populate the room types for a resort (hotel) in a drop down menu if the rooms types are more than one for a particulate hotel (resort)?

I am developing an online travel bookings system. Infact i bought a an online booking system and I am modifying it to my needs. The problem here is with the check availability form for a particular resorts or hotels. I want to populate a dropdown menu with room types for that particular hotel but im not able to populate the dropdown menu if the hotel has more than one room types

Here is the particular code which asks to populate the dropdown menu

 $result_room = $db->query("SELECT * FROM pm_room WHERE checked = 1 AND id_hotel = '.$hotel_id.' AND lang = ".LANG_ID); 

The table for rooms is "pm_room" and in that table there is a column for hotel id which is "id_hotel"

The file im modifying is search-min.php

here below is the code in search-min.php

<?php
debug_backtrace() || die ("Direct access not permitted");

$max_adults_search = 5;
$max_children_search = 10;

if(!isset($_SESSION['destination_id'])) $_SESSION['destination_id'] = 1;
if(!isset($destination_name)) $destination_name = "";

if(!isset($_SESSION['num_adults']))
    $_SESSION['num_adults'] = (isset($_SESSION['book']['adults'])) ? $_SESSION['book']['adults'] : 1;
if(!isset($_SESSION['num_children']))
    $_SESSION['num_children'] = (isset($_SESSION['book']['children'])) ? $_SESSION['book']['children'] : 0;

$from_date = (isset($_SESSION['from_date'])) ? $_SESSION['from_date'] : "";
$to_date = (isset($_SESSION['to_date'])) ? $_SESSION['to_date'] : ""; ?>

<form action="<?php echo DOCBASE.$sys_pages['booking']['alias']; ?>" method="post" class="">
    <?php
    if(isset($hotel_id)){ ?>
        <input type="hidden" name="hotel_id" value="<?php echo $hotel_id; ?>">
        <?php
    } ?>



<div class="form-group">
    <label class="sr-only" for="from"></label>
    <div class="input-group">
        <div class="input-group-addon"><i class="fa fa-calendar"></i> <?php echo $texts['CHECK_IN']; ?></div>
        <input type="text" class="form-control" id="from_picker" name="from_date" value="<?php echo $from_date; ?>">
    </div>
</div>
<div class="form-group">
    <div class="input-group">
        <div class="input-group-addon"><i class="fa fa-calendar"></i> <?php echo $texts['CHECK_OUT']; ?></div>
        <input type="text" class="form-control" id="to_picker" name="to_date" value="<?php echo $to_date; ?>">
    </div>
</div>





<div class="form-group">
    <div class="input-group">
        <div class="input-group-addon"><i class="fa fa-tags"></i> <?php echo $texts['ROOM']; ?></div>
        <select class="form-control" name="room_id">
            <?php


            $result_room = $db->query("SELECT * FROM pm_room WHERE checked = 1 AND id_hotel = '.$hotel_id.' AND lang = ".LANG_ID);


            if($result_room !== false){
                foreach($result_room as $i => $row){ ?>
                    <option value="<?php echo $row['id']; ?>"><?php echo $row['title']; ?></option>
                    <?php
                }
            } ?>
        </select>
    </div>
</div>




<div class="form-group">
    <div class="input-group">
        <div class="input-group-addon"><i class="fa fa-male"></i> <?php echo $texts['ADULTS']; ?></div>
                    <select name="num_adults" class="selectpicker form-control">
                        <?php
                        for($i = 1; $i <= $max_adults_search; $i++){
                            $select = ($_SESSION['num_adults'] == $i) ? " selected=\"selected\"" : "";
                            echo "<option value=\"".$i."\"".$select.">".$i."</option>";
                        } ?>
        </select>
    </div>
</div>
<div class="form-group">
    <div class="input-group">
        <div class="input-group-addon"><i class="fa fa-male"></i> <?php echo $texts['CHILDREN']; ?></div>
                    <select name="num_children" class="selectpicker form-control">
                        <?php
                        for($i = 0; $i <= $max_children_search; $i++){
                            $select = ($_SESSION['num_children'] == $i) ? " selected=\"selected\"" : "";
                            echo "<option value=\"".$i."\"".$select.">".$i."</option>";
                        } ?>
                    </select>
    </div>
</div>



<div class="form-group">
    <button class="btn btn-primary" type="submit" name="check_availabilities"><i class="fa fa-search"></i> <?php echo $texts['CHECK']; ?></button>
</div>
</form>

With this code it populates the drop down menu for rooms if the hotel has only one room type: eg: https://www.thesandsmaldives.com/resorts/niyama

But if the hotel has more than one room type it doesn't populate the drop down for the room types. eg: https://www.thesandsmaldives.com/resorts/oblu-by-atmosphere-at-helengeli

What am i doing wrong here?

I figured it out with the help of its original coders from who i bought it, its a Syntax error. I was using single quote AND double quotes. Use one or the other but not both ;) I just seen it's my bad,

All room types are stored in pm_room table but there is a hotel id column in that table to pinpoint for which hotel the room type is for the correct code is

$result_room = $db->query("SELECT * FROM pm_room WHERE checked = 1 AND id_hotel = ".$hotel_id." AND lang = ".LANG_ID);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM