Jump to content

Archived

This topic is now archived and is closed to further replies.

kikilahooch

displaying data from database into dropdown menus

Recommended Posts

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:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body background="busback.jpg">
<center>
<p>
<img height="58" alt="" src="hr_top.gif" width="680" border="0"></p>

<table cellspacing="0" cellpadding="0" width="1004" border="0" mm:layoutgroup="true">
<tbody>
<tr>
<td valign="top" width="200" height="517">
</td>
<td valign="top" width="597"> 


<!-- - - - - -Begin editable text - - - - - - - - -->
<p><font color="#000000" size="+1"><b>Wish to check a route?</b></font> </p>
<p><font color="#000080">Fill in the information below and click search </font></p>
<form action="bustrain.php" method="post">
<p>
<table width="100%" border="0" align="right"><!--p
      if (isset($message_new))                                 
          echo "<tr><td colspan='2'><b>$message_new</b></td></tr>";
  -->
<tbody>
<tr>
<td align="right"><font color="#000080"><b>destination:</b></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";

$query1 = "SELECT destination
FROM bus
WHERE source = ’Wexford’
UNION
SELECT destination
FROM train
WHERE source = ’Wexford’;
"

//Query to return the routes available from
//the first query, in this case, routes available
//from Wexford.
$result1 = @mysql_query($query1, $connection)
//The results above should then be placed in a menu
print "<form>\n" .
"\t<select>\n"
while ($row = @mysql_fetch_row($result1))
{
print "\n<option value=\"{$row[’destination’]}\""
}
print "\n\t</selected>"
print "\n</form>"






<tr>
<td align="right"><font color="#000080"><b>Travelling:</b></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>
<br>
<a href="contactus.html" target="mainFrame">Contact US | </a>
<a href="bus.html" target="mainFrame">Bus Search Search | </a>
<a href="train.html" target="mainFrame">Train Search | </a>
<a href="timetable.html" target="mainFrame">Timetables</a>


</body>
</html>


The second page is called bustrain.php and the code for this is here:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>bus search</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><font color="navy">

<p><img src="hr_top.gif" width="680" height="58" border="0"></p>
 
                           



<?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"><b>Source</b></td>

<td align="left" bgcolor="#0099CC"><center><font color="white"><b>Destination</b></td>

<td align="left" bgcolor="#0099CC"><center><font color="white"><b>Departure Time</b></td>

<td align="left" bgcolor="#0099CC"><center><font color="white"><b>Arrival Time</b></td>

<td align="left" bgcolor="#0099CC"><center><font color="white"><b>Travel Day</b></td>

<td align="left" bgcolor="#0099CC"><center><font color="white"><b>Operator</b></td>

<td align="left" bgcolor="#0099CC"><center><font color="white"><b>Price</b></td>

<td align="left" bgcolor="#0099CC"><center><font color="white"><b>Purchase</b></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();

?>
</font>
</body>
<center>
<p><img src="hr_bot.gif" width="680" height="44" border="0"> </p>
<br>
<a href="contactus.html" target="mainFrame">Contact US | </a>
<a href="bus.html" target="mainFrame">Bus Search Search | </a>
<a href="train.html" target="mainFrame">Train Search | </a>
<a href="timetable.html" target="mainFrame">Timetables</a>

</center>
</html>



If anyone can help i would really appreciate it.

Share this post


Link to post
Share on other sites
You copy and pasted all the page's code.....
Anyway i will give u a code i usually use in my project
It will display data from ur database and put them in a dropdown box
[code]
<select name="SELECT_NAME" id="SELECT_NAME">
        <?
  $SQL = mysql_query("SELECT destination FROM bus WHERE source = ’Wexford’ UNION SELECT destination FROM train WHERE  source = ’Wexford’);
  while ( $row = mysql_fetch_object($SQL) ):
  ?>
        <option value="<? echo $row->DESTINATION_ID?>"><? echo $row->DESTINATION_NAME?></option>
        <? endwhile?>
        </select>
[/code]

Just replace:
1- SELECT_NAME with the name of the select you want
2- DESTINATION_ID with the name of the select you want
3- DESTINATION_NAME with the name of the select you want

Hope this do the trick for you

JoKinG


Share this post


Link to post
Share on other sites
Should i have all of the code in one php file or should i use 2 seperate pages?? a html and a php. I'm not too sure where this code should be inserted??

Share this post


Link to post
Share on other sites
This code should be inserted where you want the drop down box to be.

example:
[code]
<table width=100%>
<tr>
<td>Countries</td>
<td><?PHP THE CODE I GAVE YOU ?></td>
</tr>
</table>
[/code]

JoKinG

Share this post


Link to post
Share on other sites
You shouldnt post ur username and password in public.... plz remove them now.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.