Hi guys,
I’ve nearly got this code working but just can’t figure why my data is missing the very first record. To explain:
i have 2 tables in my mysql database, tv_category_sub and tv_category_sub_sub. The two tables are linked together by the column tv_sub_id.
my code is as follows:
<?php
echo '<table cellspacing="5" cellpadding="5" align="left">';
$result = mysql_query("SELECT a.tv_sub_name, b.tv_sub_sub_name, b.tv_sub_sub_id FROM tv_category_sub_sub b LEFT JOIN tv_category_sub a ON a.tv_sub_id = b.tv_sub_id ORDER BY a.tv_sub_name, b.tv_sub_sub_name ASC") or die("SELECT error: " . mysql_error());
$columns_counter=0;
echo '<tr>';
$currentCat = '';
while($row = mysql_fetch_array($result)) {
$subcat = $row['tv_sub_name'];
$subsubid = $row['tv_sub_sub_id'];
$subsubcat = $row['tv_sub_sub_name'];
extract($row);
if ($currentCat != $subcat) {
//if a new category, write category head
echo "<tr><td colspan=\\"3\\"><h4>$subcat TV brackets</h4></td></tr>";
$currentCat = $subcat;
} else {
echo '<td align = "left">';
echo $subsubcat . ' - ' . $subsubid;
}
echo '</td>';
$columns_counter++;
if($columns_counter==3)
{
echo '</tr><tr>';
$columns_counter=0;
}
}
echo '</tr></table>';
?>
what i what to display is this
TV-Category 1(tv_sub_name)
TV-Sub 1 TV-Sub 2 TV-Sub 3
TV-Sub 4
(tv_sub_sub_name)
TV-Category 2
TV-Sub 1 TV-Sub 2 TV-Sub 3
TV-Sub 4
…and so on
However what I’m getting is this
TV-Category 1(tv_sub_name)
TV-Sub 2 TV-Sub 3
TV-Sub 4
(tv_sub_sub_name)
TV-Category 2
TV-Sub 2 TV-Sub 3
TV-Sub 4
It looks like it’s counting the tv_sub_name (i.e the main category) as the first record and jumping to the second record for tv_sub_sub_name (the sub category). Can anyone help and show me where I’m going wrong? Hope you can understand what I’m saying.