Welcome Guest, Not a member yet? Register   Sign In
Generating results from a database depending on a completely seperate query.
#2

[eluser]mddd[/eluser]
In your second query you are selecting from " room_bookings left join bookings ". But in the end you want to show the rooms by booking. So you are doing it the wrong way around. You need to put the main thing (bookings) left and the secondary thing (rooms) right.

Also, you can easily combine your queries. Why do you first look up the bookings and then the rooms separately? Joining them is easy.
Your total query should then be
Code:
SELECT bookings.id, bookings.title, GROUP_CONCAT(room_bookings.room_name) AS names
FROM bookings
LEFT JOIN room_bookings ON room_bookings.booking_id = bookings.id
WHERE bookings.status=0
GROUP BY bookings.id

In this code, I also grouped the rooms for each booking together (GROUP BY bookings.id). You'll get a single result for each booking. The names
of the rooms will be in there, separated by commas. That's from the GROUP_CONCAT command.

Now it is totally easy to display the result:
Code:
foreach ($bookingsresult as $booking)
{
  Booking name: <?=$booking['title']?>
  Rooms booked: <?=$booking['names']?>
}


Messages In This Thread
Generating results from a database depending on a completely seperate query. - by El Forum - 07-29-2010, 08:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB