Hey guys.
I'm trying to get values from a database to display properly, so that I get the following in a <select> field:
2005
Construction Photos
2004
Events
General
Lifeguards
Old Pool
Panoramic
Now, I have tried GROUP BY b.cyid (where cyid is the id of the Year that they happened in), but that will only return the first of each. So I took the group by out, then I got each item with each year, so that it looked like:
2005
Construction Photos
2004
Construction Photos
How would I go about doing this? I'm truly at a stand still. Here's the code I have:
$query = "SELECT * FROM `Years` a, `Categories` b ORDER BY `b`.cid DESC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
echo "<optgroup label='".$row['Year']."'>";
echo "<option value='".$row['cid']."'>".$row['Category']."</option>";
echo "</optgroup>";
}
I also tried joining them, but couldn't get it to work, as per the mySQL website. I'm betting that i have to join them, but what is the correct way?
Any help you can offer would be great.
~Brett