Im trying to display multiple row values in one column. Im using 4 tables which consist of a one to many relationship. I have built a query with the data I will need, Im not sure if the issue lyes here or actually on the PHP side. I have included some code so you can get an idea. I honestly think I may need to use GROUP BY or include a foreach loop after the while to get the result I want. If someone could point me in the right direction or guide me to a solution it would be much appreciated.
I can stop Category duplication by using GROUP BY category_name, but Im having problems with the subCat_name not showing all the results. Only displays the first row. It should show all subCat_name under the main category_name
Currently getting this
Ideas (category_name)
Shop More( subCat_name)
Have a better wardrobe(subCat_description)
But it should be like
Ideas (category_name)
Shop More( subCat_name)
Have a better wardrobe(subCat_description)
Build a Blog( subCat_name)
Share Ideas(subCat_description)
Travel to NYC( subCat_name)
Book a holiday(subCat_description)
MYSQL QUERY
$query = 'SELECT project_users.*, project.project_name, category.category_name, sub_category.subCat_name, sub_category.subCat_description
FROM project_users
JOIN project
ON project.project_id = project_users.project_id
JOIN category
ON category.project_id = project.project_id
JOIN sub_category
ON sub_category.category_id = category.category_id';
PHP
$result = mysqli_query($link, $query);
if($result) {
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo '<!-- category container for tasks-->
<div class="col-lg-4 category">
<section class="panel">
<div class="panel-body">
<header class="to-do-head">';
echo '<h3>' . $row['category_name'] . '</h3>';
echo ' <a class="to-do pull-right"><i class="icon-plus"></i> Add Task</a>';
echo '</header>';
echo '<div class="col-lg-12 task"><!--open task-->';
echo '<div class="panel-body">';
echo '<h4>' . $row['subCat_name'] . '</h4>';
echo '<p>' . $row['subCat_description'] . '</p>';
echo '</div><!--close panel-body-->';
echo '<div class="task-foot">';
echo '<a href=""><i data-original-title="Add Action" class="icon-legal tooltips"></i></a>
<p class="pull-right"><i class="icon-calendar"></i> 16th Jan 2014</p>
</div><!--close task foot-->';
echo '</div><!--close-lg-12 task-->';
echo '</div><!--close panel body-->
</section><!--close panel-->
</div><!--col lg 4 close container for tasks-->';
}//end while