I have what is probably a basic question, but am new to web development, so don't really know where to look for an answer. Any help is greatly appreciated as I have brick-walled on this one.
I have a database of events that are organized by grandparent-parent-event_name structure. So Grandparent might be "Baseball" Parent might be "New York Mets" and Event Name would be "Mets vs. Phillies".
If the following form, I let an admin choose one option from each level of categorization. I have two questions:
1. Is there a better way to do this than with three db queries? (By "better" I mean less taxing on db and with faster page loads)
2. Is there a way, without using Javascript, that when someone chooses "Baseball" from grandparent, the options for parent would be limited to baseball teams and exclude football teams, golf matches, etc.? Would I need a submit button by each drop down? Do I need a separate file?
<form action="create_any_page.php" method="post">
<!-- Grandparent Selector -->
Grandparent Name:
<?php $query_grandparent = "SELECT DISTINCT grandparent FROM events ORDER BY grandparent asc";
$result_grandparent = mysql_query($query_grandparent) or die(mysql_error());
$options_grandparent = "";
while ($row_grandparent = mysql_fetch_array($result_grandparent)) {
$the_grandparent = $row_grandparent["grandparent"];
$options_grandparent.="<OPTION VALUE=\"$the_grandparent\">".$the_grandparent."</option>";
}
?>
<select name='grandparent'><option value=0>Choose<?=$options_grandparent ?></select><br />
<!-- Parent Name Selector -->
Parent Name:
<?php $query_parent = "SELECT DISTINCT parent FROM events ORDER BY parent asc";
$result_parent = mysql_query($query_parent) or die(mysql_error());
$options_parent = "";
while ($row_parent = mysql_fetch_array($result_parent)) {
$the_parent = $row_parent["parent"];
$options_parent.="<OPTION VALUE=\"$the_parent\">".$the_parent."</option>";
}
?>
<select name='parent_name'><option value=0>Choose<?=$options_parent_name?></select><br />
<!-- Event Name Selector -->
Event Name:
<?php $query_event_name = "SELECT DISTINCT event_name FROM events ORDER BY event_name asc";
$result_event_name = mysql_query($query_event_name) or die(mysql_error());
$options_event_name = "";
while ($row_event_name = mysql_fetch_array($result_event_name)) {
$the_event_name = $row_event_name["event_name"];
$options_event_name.="<OPTION VALUE=\"$the_event_name\">".$the_event_name."</option>";
}
?>
<select name='event_name'><option value=0>Choose<?=$options_event_name?></select><br />
<input type='submit' />
</form>