Thanks for all your help everyone! This is what I have come up with but it still is not working correctly:
$result = mysql_query("SELECT mcat .mcat_name AS Main,
scat .scat_name AS Sub
FROM mcat INNER JOIN scat
ON mcat.mcatID = scat .maincat");
if (!$result) {
echo "Error in the database!!!";
exit;
}
$previous_main = "";
while ($record = mysql_fetch_assoc($result)) {
if (!$record["Main"] == $previous_main) {
echo "<h2>".$record["Main"]."</h2>";
}
echo " <font color='red'>".$record["Sub"]."</font> |";
$previous_main = $record["Main"];
}
For some reason, when the main category changes, the if statement isnt detecting it so it doesnt write the next categories <h2> statement. If this a valie if statement?
if (!$record["Main"] == $previous_main)