I am working on a booth booking system. Customer can choose booth and the day to book.

Each selected check box will store in a booking ID after press button Reserve (etc: 3 checked box = 3 booking ID).
When I display all the booking, it will display all the booth and the day. If I book a same booth for 3 days, it will display separately in 3 rows.

How I want to modify my coding so that I can display same booth and its corresponding days in a single row as show below:

Here is my coding:
<?php
include("dbconfig.php");
$query4 = "SELECT bookingID,eventinfo.eventTitle,boothAlias,testbook.bstatus,date,day, username FROM eventinfo, testbook WHERE username='$user' AND testbook.eventID = eventinfo.eventID order by date desc";
//$query4="select * from testbook, eventinfo where username= '$user' and testbook.'$event'==eventinfo.'$event' order by eventID asc";
$result4 = mysql_query($query4);
while($row=mysql_fetch_array($result4))
{
$booth=stripslashes($row["boothAlias"]);
$day=stripslashes($row["day"]);
$event= stripslashes($row["eventTitle"]);
$date=stripslashes($row["date"]);
$bstatus=stripslashes($row["bstatus"]);
if ($bstatus==0){
echo "<tr class='record'>";
echo "<td class='reg' width='80'>$booth</td>";
echo "<td class='reg' width='80'>$day</td>";
echo "<td class='reg' width='180'>$event</td>";
echo "<td class='reg' width='150'>$date</td>";
echo "<td class='reg' width='70'><img src='icon_stop.gif'/></td>";
echo "<td class='reg' width='30'><a id='$row[bookingID]' style='color:#ff0000;' class='delbutton' href='#'><img src='icon_delete.gif' border='0'></a></td></tr>";
}else{
echo "<tr class='record'>";
echo "<td class='reg' width='80'>$booth</td>";
echo "<td class='reg' width='80'>$day</td>";
echo "<td class='reg' width='180'>$event</td>";
echo "<td class='reg' width='150'>$date</td>";
echo "<td class='reg' width='70'><img src='icon.approve.gif'/></td>";
echo "<td class='reg' width='30'><a id='$row[bookingID]' style='color:#ff0000;' class='delbutton' href='#'><img src='icon_delete.gif' border='0'></a></td></tr>";
}
}
?>
Your query needs a
GROUP BYclause, along with theGROUP_CONCAT()aggregate function:This is untested, but should do what you want. If you get an incorrect result, change what fields you use in your
GROUP BYclause.In your query, you’re using an implicit join, which isn’t as good as using an explicit join. Without knowing your table structure, I can’t edit the query into an explicit join, but you should look this up and convert it yourself. It’ll save you many a headache with larger queries.