3 dependable combo box problem

Discussion in 'PHP' started by n747, Mar 13, 2010.

  1. n747

    n747 New Member

    Joined:
    Mar 13, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    here I have a issue regading 3 dependable combo box ....Please Help me...
    :nonod::nonod:

    I created three dependable combo boxes as follows.but when country select all hotels
    showed due to country.really I need when select country shows related city and
    when select city shows related hotels...So,Please give me a solution .

    ----------------java script -----------------------------------
    Code:
    function selectcountry(){
    
    var selected_index = document.getElementById('country').selectedIndex;
    var selected_value = document.getElementById('country').options[selected_index].value;
    if(selected_value !='0'){
    window.location = 'index.php?c_id='+ selected_value;
    }
    }
    
    ---------------------------------------------------------
    Code:
    <table width="64%" border="0" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
    <tr>
    <td width="43%"><img src="images/logo.gif" width="273" height="81" /></td>
    <td width="43%" valign="top"> <div align="justify"><span class="style1">Srilanka.com travel professionals are fully &quot;in the know&quot; about all the places to go, things to do and special offers to Sri Lanka &amp; Maldives. They are trained and qualified and are very keen to help organize and book your perfect holiday. </span></div></td>
    <td width="14%"><div align="center"><img src="images/flower_sri.jpg" width="62" height="66" /></div></td>
    </tr><form id="form1" name="form1" method="post" action="selecttype.php">
    <tr>
    <td><em><strong>Quick Search </strong></em></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td><div align="right">Country</div></td>
    <td><label>
    <select name="country" id="country" onChange="selectcountry()">
    <option value="">Select a Country</option>
    <?php
    $result = mysql_query("select * from country ORDER BY cname ASC");
    
    while($data = mysql_fetch_array($result)){
    $cid = $data['cid'];
    $_SESSION['country id'] = $countryid;
    $cname = $data['cname'];
    if($_GET['c_id']== $cid){
    ?>
    <option selected="selected" value="<?php echo $cid; ?>"><?php echo $cname ?></option>
    <?php
    }else{
    ?>
    <option value="<?php echo $cid; ?>"><?php echo $cname ?></option>
    <?php
    }
    }
    ?>
    </select>
    </label></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td height="26"><div align="right">City</div></td>
    <td><label>
    <select name="city" id="city">
    <option value="">Select a City</option>
    <?php
    if(isset($_GET['c_id']))
    {
    $cid = $_GET['c_id'];
    $result2 = mysql_query("select * from city where cid = $cid ");
    while($data2 = mysql_fetch_array($result2)){
    $cityid = $data2['cityid'];
    $_SESSION['city id'] = $cityid;
    $city_name = $data2['city_name'];
    if($_GET['c_id']== $cityid){
    ?>
    <option selected="selected" value="<?php echo $cityid; ?>"><?php echo $city_name ?></option>
    <?php
    }else{
    ?>
    <option value="<?php echo $cityid; ?>"><?php echo $city_name ?></option>
    <?php
    }
    }
    ?>
    </select>
    <?php
    }
    ?>
    </label></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td><div align="right">Hotel Name </div></td>
    <td><label><select name="hotel" id="hotel">
    <option value="">Select a Hotel</option>
    <?php
    if(isset($_GET['c_id']))
    {
    $ciid = $_GET['c_id'] ;
    echo $ciid;
    $result3 = mysql_query("select * from hotel where cid = $ciid "); ///here it must be comes due to city id not country id.....but noe it comes due to country
    while($data3 = mysql_fetch_array($result3)){
    $hotelid = $data3['hid'];
    $_SESSION['hotelid'] = $hotelid ;
    $hotelname = $data3['hname'];
    ?>
    <option value="<?php echo $hotelid; ?>"><?php echo $hotelname; ?></option>
    <?php
    }
    
    
    ?>
    </select>
    <?php
    }
    ?>
    </label></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><label>
    <input type="submit" name="submit" value="Find a Hotel" />
    </label></td>
    </table>
    
    --------------Database-----------
    Code:
    INSERT INTO `country` (`cid`, `cname`) VALUES
    (1, 'UK'),
    (2, 'USA');
    
    ------------------
    INSERT INTO `city` (`cityid`, `cid`, `city_name`) VALUES
    (1, 1, 'uuuuu'),
    (2, 1, 'tttttt'),
    (3, 1, 'dsss'),
    (4, 1, 'dfggdgg'),
    (5, 2, 'AAAAA'),
    (6, 2, 'BBBBBB');
    
    ------------
    CREATE TABLE IF NOT EXISTS `hotel` (
    `hid` int(10) NOT NULL AUTO_INCREMENT,
    `cid` int(10) NOT NULL,
    `cityid` int(10) NOT NULL,
    `hname` varchar(50) NOT NULL,
    `haddress` text NOT NULL,
    `hemail` varchar(50) NOT NULL,
    `htelno` varchar(20) NOT NULL,
    `hlocation` text NOT NULL,
    `hdining` text NOT NULL,
    `h_con_person` varchar(30) NOT NULL,
    `hspecial` text NOT NULL,
    `hfax` varchar(30) NOT NULL,
    PRIMARY KEY (`hid`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
    
    Pls I need Someone help.......Thanks In Advanced
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice