Forum Moderators: coopster
<form method=post>
<select>
<?
$sql="SELECT author FROM quotes GROUP BY author ASC";
$result = mysql_query($sql);
//display authors in select box
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {;
$author = $row["author"];
echo "<option name='$author'>$author</option>";
}
?>
</select>
</form>
Does that look right?
How do I display the quotes that match the author they select? Some authors have several quotes in the database.
Any help would be appreciated. Thanks.
To get your second select box dynamically populated with the quotes by a given author, however, is going to require some JavaScript. Either create arrays of all quotes for each author when you query the database, then write a JS function that's triggered by an onchange event in the author select box to repopulate the quote select box with the appropriate author's array of quotes, OR use an onchange="this.form.submit()" event in the author select box, which would send the form data back to the server whenever an author change is made, and where you'd do a query for the given author's quotes to repopulate the quote select box.
I hope this helps.
OR use an onchange="this.form.submit()" event in the author select box, which would send the form data back to the server whenever an author change is made, and where you'd do a query for the given author's quotes to repopulate the quote select box.
I think that's what I want to do, except the quotes won't actually need to display in a select box, they'll just display on the screen (sorry I wasn't very clear). The trouble I'm having is figuring out how to query the database to get the authors quotes. How would I get started on that?
;) One more point, though: You'll also need to add a form action, pointing to the script that will process the data. Like:
<form action="target_script.php" method="post">
You can use
$_SERVER['PHP_SELF'] as the target script if the form data will be processed by the same script as generates the form (probably the best idea). I wish you well.