<?php
mysql_connect("localhost", "username", "password") or die (mysql_error()); //Connect to database
mysql_select_db("books") or die (mysql_error()); // Select database
?>
<select name="book">
<option value="0">Select Book...</option>
<?php
$query = mysql_query("SELECT book FROM `table` GROUP BY book"); // Select all books from the database and group by books
while ($r = mysql_fetch_array($query)) { // Loop through the results
echo "<option value=\"".$r['book']."\">".$r['book']."</select>"; // Display each result in the list box
}
?>
</select>
<select name="chapter">
<option value="0">Select Chapter...</option>
<?php
if (isset($_POST['book'])) { // Check if we have a book to look for
$book = preg_replace("/[^0-9A-Za-z\s]/", "", $_POST['book']); // Strip any unwanted characters out
$query = mysql_query("SELECT chapter FROM `table` GROUP BY chapter WHERE `book` = '".$book."'"); // Select the chapters from the book and group by the chapter
while ($r = mysql_fetch_array($query)) {
echo "<option value=\"".$r['chapter']."\">".$r['chapter']."</select>";
}
}
?>
</select>
<select name="verse">
<option value="0">Select Verse...</option>
<?php
if (isset($_POST['chapter'])) {
$chapter = preg_replace("/[^0-9A-Za-z\s]/", "", $_POST['chapter']);
$query = mysql_query("SELECT chapter FROM `table` GROUP BY chapter WHERE `book` = '".$book."'");
while ($r = mysql_fetch_array($query)) {
echo "<option value=\"".$r['verse']."\">".$r['verse']."</select>";
}
}
?>
</select>