I am using a MySQL INNER JOIN statement which returns various results for one distinct record in the main table from the joins, similar to How to Join Multiple Joins yet return Distinct Values
My query is
SELECT cl.*, dep.dept_name
FROM epapers.clientelle cl
INNER JOIN epapers.dept_staff_users depu
ON depu.user_id=cl.user_id
INNER JOIN epapers.dept dep
ON dep.dept_id=depu.dept_id
group by cl.user_id
ORDER BY cl.user_name ASC,
I would like to display the above in a table shown below
echo "<tr bgcolor='#CCCCCC'>
<td >$num</td><td >".$row[user_id]."</td><td>".$row[user_name]."</td>
<td >".$row[fname]."</td><td >".$row[lname]."</td>
<td >".$row[dept_name]."</td>
<td >".$row[dept_name]."</td>
<td >".$row[dept_name]."</td>
<td >".$row[email]."</td>";
$TrID = "$row[user_id]";
echo "<td >";
echo '<form name="activate" action="activate_acc.php" method="POST" ;">';
echo "<input type='hidden' name='TrID' value='$TrID'>";
echo "<input type='checkbox' name='active' value='$row[active]'>";
echo '<input type="submit" name="Submit" value="Delete">';
echo '</form>';
echo "</td >";
...
Note the the departments can be upto 3 departments. How do I return the mysql query results in a single row for the departments?
If you are using MySQL you can use GROUP_CONCAT but you will have to do some post processing and it’s a bit ugly.
It’s kinda denormalisation at runtime…