I am trying to join two tables and select from 'railstp'. I have simplified the tables.
Table 'railstp' looks like below
count startdate startlocation atoc
1 2013-09-28 lester a
2 2013-09-28 nottm a
3 2013-09-20 lester a
4 2013-09-28 birm a
Table 'location' looks like below
count startlocation goodlocation
1 lester Leicester
2 nottm Nottingham
I am trying to get the 'proper' (goodlocation) description from the table 'location' to replace the abbreviated description (startlocation) and also SELECT all the locations with a startdate of 2013-09-28. If there is not a 'proper' description it would be great if I just show the abbreviated description
So the result I am looking to achieve is
2013-09-28 Leicester a
2013-09-28 Nottingham a
2013-09-28 birm a
My code is as below:-
require('connect_db.php');
mysqli_select_db($mysql_link,"Timetable");
function show_records($mysql_link)
{
$q="SELECT railstp.startdate,railstp.startlocation,railstp.atoc,location.startlocation,location.goodlocation
FROM railstp
LEFT JOIN location
ON railstp.startlocation=location.startlocation
WHERE railstp.startdate='2013-09-28'
ORDER BY startdate";
$r=mysqli_query($mysql_link,$q);
if ($r)
{
echo "<Table id='customers'>
<tr>
<th>From</th>
<th>Departing</th>
<th>ATOC</th>
</tr>";
while ($row=mysqli_fetch_array($r,MYSQLI_ASSOC))
{
echo "<tr>";
echo "<td>".$row['startdate']."</td>";
echo "<td>".$row['startlocation']."</td>";
echo "<td>".$row['atoc']."</td>";
echo "</tr>";
}
echo "</Table>";
}
else {echo '<p>'.mysqli_error($mysql_link).'</p>' ;}
}
show_records($mysql_link);
mysqli_close($mysql_link);
The selection does not show the 'Proper' (goodlocation) description - ie it should show Nottingham instead of nottm and Leicester instead of lester
Thank you for your help