Jump to content

sql statement to select from multiple tables


debcous

Recommended Posts

<?php
include "db.php";

$submit=$HTTP_POST_VARS["submit"];
$reset=$HTTP_POST_VARS["reset"];

$source =$HTTP_POST_VARS["source"];
$destination=$HTTP_POST_VARS["destination"];
$travelday=$HTTP_POST_VARS["travelday"];

$query = "SELECT * FROM bus AND train where bus.source='$source' and bus.destination='$destination' and bus.travelday='$travelday' and train.source='$source' and train.destination='$destination' and train.travelday='$travelday'";


$result = @mysql_query($query, $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></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></tr>';

echo'</table>';}

}

else{
echo'<h1> System Error </h1> table ';
exit();
}
mysql_close();

?>


Hi...I'm trying to display details from 2 seperate tabels in my database onto the screen in the form of a table. Can someone please tell me if the code i am using is correct for this function. At the moment it is displaying 'system error'. I would really appreciate your help.

Debbie
Link to comment
Share on other sites

change

$query = "SELECT * FROM bus AND train where bus.source='$source' and bus.destination='$destination' and bus.travelday='$travelday' and train.source='$source' and train.destination='$destination' and train.travelday='$travelday'";

to

$query = "SELECT * FROM bus,train where bus.source='$source' and bus.destination='$destination' and bus.travelday='$travelday' and train.source='$source' and train.destination='$destination' and train.travelday='$travelday'";


just needed , in place of AND and that should now work for you :)


Regards
Liam
Link to comment
Share on other sites

[!--quoteo(post=367997:date=Apr 24 2006, 09:45 AM:name=shocker-z)--][div class=\'quotetop\']QUOTE(shocker-z @ Apr 24 2006, 09:45 AM) [snapback]367997[/snapback][/div][div class=\'quotemain\'][!--quotec--]
change

$query = "SELECT * FROM bus AND train where bus.source='$source' and bus.destination='$destination' and bus.travelday='$travelday' and train.source='$source' and train.destination='$destination' and train.travelday='$travelday'";

to

$query = "SELECT * FROM bus,train where bus.source='$source' and bus.destination='$destination' and bus.travelday='$travelday' and train.source='$source' and train.destination='$destination' and train.travelday='$travelday'";
just needed , in place of AND and that should now work for you :)
Regards
Liam
[/quote]


i had that already but gave me the same error. does the rest of the statement look ok to you?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.