Jump to content


Photo

displaying data from database into dropdown menus


  • Please log in to reply
5 replies to this topic

#1 kikilahooch

kikilahooch
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 30 August 2006 - 11:39 AM

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.

#2 joking

joking
  • Members
  • PipPip
  • Member
  • 29 posts
  • LocationLebanon

Posted 30 August 2006 - 12:13 PM

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
<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>

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



Just JoKinG

#3 kikilahooch

kikilahooch
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 30 August 2006 - 12:18 PM

thank you :) i'll try it out now

#4 kikilahooch

kikilahooch
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 30 August 2006 - 12:28 PM

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??

#5 joking

joking
  • Members
  • PipPip
  • Member
  • 29 posts
  • LocationLebanon

Posted 30 August 2006 - 12:31 PM

This code should be inserted where you want the drop down box to be.

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

JoKinG
Just JoKinG

#6 joking

joking
  • Members
  • PipPip
  • Member
  • 29 posts
  • LocationLebanon

Posted 30 August 2006 - 04:57 PM

You shouldnt post ur username and password in public.... plz remove them now.
Just JoKinG




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users