To clarify, I am trying to get a table to output that displays my MySQL database table in a certain way. The table is populated with names, birth-years, and zodiac animals.
What I want to do is have a table row that says something like "cat zodiac signs" and then a heading of "name" and "birth year". Under that I want each persons' name and year they were born. I want this done for each zodiac animal.
The issue I am having is that the heading for is displaying each instance of the zodiac column. I know my code is wrong, I am just not sure what to do next! Please help! Here is my code
$TableName = "zodiacshared";
$SQLstring = "SELECT * FROM $TableName GROUP BY sign, birthyear";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if (mysql_num_rows($QueryResult) == 0){
echo "<p> There are no entries in the chinese zodiac gallery! </p>";
}
else{
echo "<table width = '100%' border = '1'>";
while ($row=mysql_fetch_array($QueryResult)){
echo "<th colspan='2'>"; echo $row['sign']; echo " zodiac signs</th>";
echo "<tr><th>Name</th><th>Birth Year</th></tr>";
echo "<tr>";
echo "<td>"; echo $row['name']; echo "</td>";
echo "<td>"; echo $row['birthyear']; echo "</td>";
echo "</tr>";
}
echo "</table>";
mysql_free_result($QueryResult);
}
Edit: Right that may be helpful My hopeful output is something like this (this is a rough draft made on Excel, but gets point across):

edit 2: Solution was:
$current_zodiac= '';
while ($row=mysql_fetch_array($QueryResult)){
if ($row['sign']!=$current_zodiac){
echo "<th colspan='2'>"; echo $row['sign']; echo " zodiac signs</th>";
echo "<tr><th>Name</th><th>Birth Year</th></tr>";
}else{
//echo the other rows
}
echo "<tr>";
echo "<td>"; echo $row['name']; echo "</td>";
echo "<td>"; echo $row['birthyear']; echo "</td>";
echo "</tr>";
$current_zodiac = $row['sign']; //assign new zodiac to current zodiac variable
}
