Hi there everyone.
After further research and advice I am unfortunately still stuck on this one. The good news is that I believe my solution to lie within php and not an sql query statement.
The sql statement I am using at the moment is:
$sql=“SELECT *
FROM product AS p
LEFT JOIN category AS c
ON p.category_id=c.category_id
ORDER BY c.category_name”;
$result=mysql_query($sql);
if (false === $result) {
echo mysql_error();
}
When I start to loop through the rows in my tables, the output on my page looks like this:
TRAINERS
Nike
TRAINERS
Puma
TRAINERS
Addidas
SHIRTS
Polo
SHIRTS
YSL
However, my goal is to get it formatted like this:
TRAINERS
Basketball
Running
General / Casual
SHIRTS
Polo
Formal
So what I need to do in php, is eliminate all duplicate category rows.
I have put together an atrocious php attempt for you all to laugh yourselves silly over which is:
[php]<?php
// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
$rows[‘category_name’] = $category_name;
$category_name = array_unique($category_name);
?>
<?php echo $category_name; ?> |
<tr class="odd">
<td class="product-title"><?php echo $rows['items']; ?></td>
<td class="price-per-pallet" align="center">£<span><?php echo $rows['price']; ?></span></td>[/php]
Which obviously doesn’t work but the idea is to fetch the array and then use array_unique to eliminate the duplicate rows.
First of all, can someone advise me if I am even on the right lines. If I am can you advise what I would need to do to make this work.
If I am heading in completely the wrong direction (bear in mind I am fumbling around in the dark), could you advise me where I need to start looking to get this working.
Many thanks in advance from a very confused novice.