Hi Folks,
I’m trying to display the following html from my query:
<h2>Aluminium</h2>
<ul>
<li>Angles11Aluminium</li>
</ul>
<li>Flat Bar11Aluminium</li>
<li>Round Bar11Aluminium</li>
<li>Square Bar11Aluminium</li>
<li>Box Section11Aluminium</li>
<li>Channel11Aluminium</li>
<li>Chequer Plate5 Bar Chequer Plate.jpg11Aluminium</li>
<li>Round Tube11Aluminium</li>
<li>Square Tube11Aluminium</li>
<h2>Stainless Steel</h2>
<ul>
<li>Flat Bar44Stainless Steel</li>
</ul>
<li>Round Bar44Stainless Steel</li>
<li>Square Bar44Stainless Steel</li>
<li>Polished Sheet44Stainless Steel</li>
<li>Plain Sheet44Stainless Steel</li>
<h2>Plastic</h2>
<ul>
<li>Acetal Round Bar33Plastic</li>
</ul>
<li>End Caps for Tubes33Plastic</li>
<h2>Brass</h2>
<ul>
<li>Flat Bar22Brass</li>
</ul>
<li>Round Bar22Brass</li>
<li>Square Bar22Brass</li>
<li>Sheet22Brass</li>
However It closes the UL tag after the first sub item, can anyone help me output it properly?
Loop :
$query="SELECT *
FROM productCat
INNER JOIN productType ON productCat.productCattype = productType.productTypeId ORDER BY catid";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
if ($cur_catid != $row['productTypeId']){ //first record in this category
echo "<h2>" . $row['productTypeName'] . "</h2><ul>";
}
echo "<li>" . $row['CatName'] . $row['catImage'] . $row['productCatType'] . $row['productTypeId'] . $row['productTypeName'] . "</li>";
if ($cur_catid != $row['productCatType']){ //get last
echo "</ul>";
}
$cur_catid = $row['productTypeId'];
}
SQL table:
catID CatName productCatType productTypeId productTypeName
1 Angles 1 1 Aluminium
2 Flat Bar 1 1 Aluminium
3 Round Bar 1 1 Aluminium
4 Square Bar 1 1 Aluminium
5 Box Section 1 1 Aluminium
6 Channel 1 1 Aluminium
7 Chequer Plate 1 1 Aluminium
8 Round Tube 1 1 Aluminium
9 Square Tube 1 1 Aluminium
10 Flat Bar 4 4 Stainless Steel
11 Round Bar 4 4 Stainless Steel
12 Square Bar 4 4 Stainless Steel
13 Polished Sheet 4 4 Stainless Steel
14 Plain Sheet 4 4 Stainless Steel
15 Acetal Round Bar 3 3 Plastic
16 End Caps for Tubes 3 3 Plastic
17 Flat Bar 2 2 Brass
18 Round Bar 2 2 Brass
19 Square Bar 2 2 Brass
20 Sheet 2 2 Brass