Hey guys.
I have a simple yet complex question here....
I have 3 tables that store information, all related to eachother. They are named: Years, Categories, Events. Each category has it's own ID (yid, cid, eid) and then a space for the id(s) of the table above it: (cyid, ecid, eyid).
I am trying to select certain information from the tables. So I set up my query to grab each table as 'a', 'b', 'c'. But, here's where my problem lies:
Can I call similar while() loops multiple times, or is that not allowed?
I.e.
I want to loop through all the values for Years, then break, and loop through all the values for Categories, ordered by Year ID, then loop through all the Events grouped by 'Cateogry'. Is this possible with 1 sql query? Here's what I have so far:
$yquery = "SELECT * FROM `Years` ORDER BY yid";
$yresult = mysql_query($yquery);
$cquery = "SELECT * FROM `Categories` ORDER BY cid";
$cresult = mysql_query($cquery);
$equery = "SELECT * FROM `Events` a, `Categories` b GROUP BY `b`.Category";
$eresult = mysql_query($equery);
for($i; $i<=$max; $i++){
echo "<form method='POST' action='upload.php' enctype='multipart/form-data' name='upload".$i."'>";
echo "<input type='hidden' name='number' value='".$max."' />";
echo "Year: <select name='year".$i."'>
<option value='null' selected>Please Select From Below</option>";
while($y = mysql_fetch_array($yresult)){
echo "<option value='".$y['yid']."'>".$y['Year']."</option>";
}
echo "</select><br /><br />
Category: <select name='cat".$i."'>
<option value='null' selected>Please Select From Below</option>";
while($c = mysql_fetch_array($cresult)){
echo "<option value='".$c['cid']."'>".$c['Category']."</option>";
}
echo "</select><br /><br />
Event: <select name='event".$i."'>
<option value='null' selected>Please Select From Below</option>";
while($e = mysql_fetch_array($eresult)){
echo "<optgroup label='".$e['Event']."'>";
while($e['ecid'] == $e['cid']){
echo "<option value='".$e['eid'].'>['.$e['eyid'].'] '.$e['Event'].'</option>';
}
echo "</optgroup>";
}
echo "</select><br /><br />
Photograph: <input type='file' name='photo".$i."' size='50' /><br />";
}
Running 3 different queries is not something I want. I would love to pull it down to 1 huge query.
Of course, if I can run the fetch_mysql_array() mutltiple times, that would be fine as well.
Thanks for the help.
~Brett