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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    displaying data from database into dropdown menus

    can somebody please have a look at this code for me please. I'm trying to display data from a bus and train table in the database. When a user selects a source from the the fordt drop down menu, the destainations available from this source should be displayed in the second drop down and the same in the last drop down. The purpose of this is to allow for connecting journeys...if the user needs to take 2 buses/trains etc to get to the final destination. I am using 2 pages for this...the first one called bustrain. html. The code for this is below:

    Code:
    <table width="100%" border="0" align="right"><!--p
          if (isset($message_new))                                  
               echo "<tr><td colspan='2'>$message_new</td></tr>";
       -->
    <tbody>
    <tr>
    <td align="right"><font color="#000080">destination:</font></td>
    <td><select name="source"> 
    <option value="Select Departure" selected="selected">Select Departure</option> 
    <option value="Waterford">Waterford</option> 
    <option value="Carlow">Carlow</option> 
    <option value="Cavan">Cavan</option> 
    <option value="Clare">Clare</option> 
    <option value="Cork">Cork</option> 
    <option value="Donegal">Donegal</option> 
    <option value="Dublin">Dublin</option> 
    <option value="Galway">Galway</option> 
    <option value="Kerry">Kerry</option> 
    <option value="Kildare">Kildare</option> 
    <option value="Kilkenny">Kilkenny</option> 
    <option value="Laois">Laois</option> 
    <option value="Leitrim">Leitrim</option> 
    <option value="Limerick">Limerick</option> 
    <option value="Longford">Longford</option> 
    <option value="Louth">Louth</option> 
    <option value="Mayo">Mayo</option> 
    <option value="Meath">Meath</option> 
    <option value="Monaghan">Monaghan</option> 
    <option value="Offaly">Offaly</option> 
    <option value="Roscommon">Roscommon</option> 
    <option value="Sligo">Sligo</option> 
    <option value="Tipperary">Tipperary</option> 
    <option value="Westmeath">Westmeath</option> 
    <option value="Wexford">Wexford</option> 
    <option value="Wicklow">Wicklow</option> 
    <option value="">None of the Above</option></select></td></tr>
    
    
    
    <tr>
    <?php 
    include "db.php";
    
    <select name="source" id="source">
            <?
    	  $SQL = mysql_query("SELECT destination FROM bus WHERE source = ’$source’ UNION SELECT destination FROM train WHERE  source = ’$source’);
    	  while ( $row = mysql_fetch_object($SQL) ):
    	  ?>
            <option value="<? echo $row->id?>"><? echo $row->destination?></option>
            <? endwhile?>
             </select>
    
    
    
    <tr>
    <td align="right"><font color="#000080">Travelling:</font></td>
    <td><select name="travelday"> 
    <option value="Select" selected="selected">Select Day</option> 
    <option value="weekday">Weekday</option> 
    <option value="weekend">Weekend</option></select></td></tr>
    <tr>
    <td>&nbsp;</td>
    <td>
    <input type="submit" value="search" name="submit"> 
    <input type="reset" value="Reset" name="reset"> </td></tr></tbody></table></p></form>
    </table>
    <p><center>
    <img height="44" alt="" src="hr_bot.gif" width="680" border="0"> </p></center>
    
    
    <a href="contactus.html" target="mainFrame">Contact US | [/url]
    <a href="bus.html" target="mainFrame">Bus Search Search | [/url]
    <a href="train.html" target="mainFrame">Train Search | [/url]
    <a href="timetable.html" target="mainFrame">Timetables[/url]
    
    
    </body>
    </html>

    The code for the PHP page is below:

    Code:
    <?php 
    include "db.php";
    
    $submit=$HTTP_POST_VARS["submit"];
    $reset=$HTTP_POST_VARS["reset"];
    
    $source =$HTTP_POST_VARS["source"];
    $destination=$HTTP_POST_VARS["destination"];
    $destination2=$HTTP_POST_VARS["destination"];
    $travelday=$HTTP_POST_VARS["travelday"];
       
    $query1 = "SELECT destination FROM bus WHERE source = "$source"
    UNION
    SELECT destination FROM train WHERE source = "$source";"
    
    $query2 = "SELECT destination FROM bus WHERE source = "$destination"
    UNION
    SELECT destination FROM train WHERE source = "Wexford";"
       
    
    
    //$query1 = "SELECT * FROM bus where bus.source = "$source" and bus.destination = "$destination"";
    
    //$query1 = "SELECT * FROM train where train.source = "$source" and train.destination = "$destination"";
    
    
    
       
       $result = @mysql_query($query1,$query2, $conn);
       if($result){
          echo'
    <table align="center" cellspacing="0" cellpadding="5" bgcolor="white" border=0 bordercolor="#0099CC" font="white">
    
    <td align="left" bgcolor="#0099CC"><center><font color="white">Source</td>
    
    <td align="left" bgcolor="#0099CC"><center><font color="white">Destination</td>
    
    <td align="left" bgcolor="#0099CC"><center><font color="white">Departure Time</td>
    
    <td align="left" bgcolor="#0099CC"><center><font color="white">Arrival Time</td>
                
    <td align="left" bgcolor="#0099CC"><center><font color="white">Travel Day</td>
    
    <td align="left" bgcolor="#0099CC"><center><font color="white">Operator</td>
    
    <td align="left" bgcolor="#0099CC"><center><font color="white">Price</td>
    
    <td align="left" bgcolor="#0099CC"><center><font color="white">Purchase</td></tr>';
                
             while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
                   echo'<tr>
                    <td align="center">'.$row['source'].'</td>
       <td align="center">'.$row['destination'].'</td>
       <td align="center">'.$row['dept_time'].'</td>
       <td align="center">'.$row['arr_time'].'</td>
       <td align="center">'.$row['travelday'].'</td>
                    <td align="center">'.$row['operator_name'].'</td>
                    <td align="center">'.$row['price'].'</td></tr>';
    
          echo'</table>';}
    
       }
       
       else{
          echo'<h1> System Error </h1> table ';
          exit();
       }
       mysql_close();
    
    ?>

    I'm not sure whether i should be using 2 pages or have everything in a single .php file instead. Should the SQL statements to populate the drop down menus be placed in the html page or the php page??

    Please Help

  • #2
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    dont understand really, but is this what your looking for:

    http://www.dynamicdrive.com/dynamici...menu/index.htm


  •  

    Posting Permissions

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