Hey guys.
I've been trying to get my join query syntax workin for a bit. For some odd reason, I can't get it to do what I want. So, I'll ask for help.
What I'm Trying To Do:
I want to populate a <select> element with entries from a database. In one database, I have 4 tables (Years, Categories, Events, Photos). Each table has a column that "links" to the previous table (Years <-- Categories <-- Events <-- Photos). So, I'm trying to create a drop-down that will give the Category as an optgroup, and list the events within that Category under the correct optgroup.
Sounds easy enough. So I started with the basic query to get the Categories as OptGroups.
$equery = "SELECT * FROM `Categories` ORDER BY cid DESC";
$eresult = mysql_query($equery);
while($e = mysql_fetch_array($eresult)){
echo "<optgroup label='".$e['Category']."'>";
// Extra stuff here
echo "</optgroup>";
}
So in order to actually populate the "children", I have to loop through a different query. This is where my problem lies. I want to have it display like so:
[YEAR] EVENT
So, here is what I tried:
$selsql = mysql_query("SELECT * FROM Years AS t1, Events AS t2 WHERE t2.ecid = '".$e['cid']."' ORDER ASC");
while($_e = mysql_fetch_array($selsql)){
echo "<option value='".$e['eid'].'>['.$_e['Year'].'] '.$_e['Event'].'</option>';
}
That returns nothing. I just get the optgroups, and no children options. I'm betting that there is something with the Joins. The 'eyid' column is populated with the ID of the row of the Year in the table Years.
I hope someone can help me out. I also hope I've made myself as clear as possible. Questions? Ask.
Thanks for any help you can offer.
~Brett