I am attempting to convert a ColdFusion script to a PHP script. The purpose of the script is to allow some one to choose a book and chapter from the Bible to display. One select box contains all 66 books of the Bible. When someone selects a book, the chapter select box is updated to display the correct number of chapters for each book of the Bible. Now here is my difficulty: Becuase I am dynamically updating the chapters select box, I must load all 1189 chapters into Java Script arrays. Thus I must loop through a MySQL query to populate this chapter array. However, when I try to do the, at random points in the script, garbage characters begin to print in places or all of the sudden the query will move from book 49 (or any number book for that matter) to book 19. Every time I refresh, it does something different. Occasionally, it will work. However after it works, when I hit refresh, the browser says that the page cannot be found. The table seems to appear fine in PHPMyAdmin. The code for all of this is here:
<?
db_connect("localhost", "BibleDB", "", "");
$getbooks = db_query("SELECT N.Book, N.BookTitle, C.Chapter, C.ChapterNum
FROM BookNames N, BibleChapters C
WHERE N.Book=C.Book
ORDER BY N.Book, C.Chapter");
$getchapters = db_query("SELECT Chapter, ChapterNum
FROM BibleChapters
ORDER BY Chapter");
$BookListBox = db_list_box($getbooks, "Book", "BookTitle"); // Puts the 66 books into an <OPTION> statement
db_data_seek($getbooks, 0);
db_disconnect();
?>
<script language="JavaScript">
<!--
// For each book, create an array to hold the chapters.
// Each book array will be identified by the book number
<?
$bibleQU = db_fetch_array($getbooks);
while($bibleQU) { ?>
// Create the array
BookArray<? echo $bibleQU['Book'] ?> = new Array();
BookArrayValue<? echo $bibleQU['Book'] ?> = new Array();
<?
$i = 0;
$temp = $bibleQU['Book']; ?>
// Populate the array
<? while($bibleQU['Book'] == $temp) ?> <? {
$i++; ?>
BookArray<? echo $bibleQU['Book'] ?>[<? echo $i; ?>] = '<? echo $bibleQU['Chapter'] ?>';
BookArrayValue<? echo $bibleQU['Book'] ?>[<? echo $i; ?>] = <? echo $bibleQU['ChapterNum'] ?>;
<? $bibleQU = db_fetch_array($getbooks); ?>
<? } ?>
<? } ?>
// Function to populate the chapters for the book selected
function PopulateChapter() {
// Only process the function if the first item is not selected.
if (document.Passage.Book.selectedIndex != 0) {
// Find the book number
var ThisBook = document.Passage.Book[document.Passage.Book.selectedIndex].value;
// Set the length of the chapters drop down equal to the length of the book's array
document.Passage.Chapter.length = eval("BookArray" + ThisBook + ".length");
// Put '---' as the first option in the chapter drop-down
document.Passage.Chapter[0].value = "";
document.Passage.Chapter[0].text = "---";
document. Passage.Chapter[0].selected = true;
// Loop through the book's array and populate the chapter drop down.
for (i=1; i<eval("BookArray" + ThisBook + ".length"); i++) {
document.Passage.Chapter.value = eval("BookArray" + ThisBook + "");
document.Passage.Chapter.text = eval("BookArrayValue" + ThisBook + "");
}
}
}
function VerifyChapter() {
if (document.Passage.Chapter[document.Passage.Chapter.selectedIndex].value == "") {
alert("Please choose a valid chapter.");
return false;
}
else {
document.Passage.submit();
}
}
//-->
</script>
This same idea works perfectly in ColdFusion, but it does not seem to work in PHP. Anybody have any ideas on what could be going wrong here? Do I need to change some settings to allow PHP to handle all 1189 records? Thanks!