I have a database with 2 tables I wish to pull data from both and display it in an html table. When I execute the below select statement I seem to get everything but the auto_increment column “id”
>mysql connection strings here.
$query = "SELECT Hotels.*,surfcup_Rates.*
FROM Hotels
LEFT JOIN surfcup_Rates
ON Hotels.id=surfcup_Rates.hotelID";
Then I use load the query into $result.
Later I load it into mysql_fetch_array and loop it into an html table.
while ($row = mysql_fetch_array($result)) {
echo "</td><td>";
echo '<a href="DeleteHotelRecord.php?id="['.$row['id'].']">Delete</a>';
echo "</td><td>";
echo $row['id'];
echo "</td><td>";
echo $row['preferred'];
>and so on...........
Everything works: the join, the select statement and data loads into the table
perfectly. All except the id column from the first table. I wish to use the id to allow the user to delete a record. The user will be adding data to the tables from a password protected “back-end” for data entry.
Is there something wrong with my select statement? Or am I missing something. Any help will be greatly appreciated.
Thank You,
Dave.
Does the
surfcup_Ratestable also have a field calledid? If so, mySQL won’t know whatidto use,hotelorsurfcup_Rates.In this case you have a couple of options,
DISCLAIMER
I have never used the following method in PHP myself, I have seen it in SAP and Zimbra, as this isn’t a discussion forum on these aspects, instead of a debate I thought I would put a disclaimer that it may not work but as mentioned above and in my comment below I have seen it work
hotels.idI hope this helps