php: populating 3 listboxes

Richlife's Avatar, Join Date: Mar 2008
Newbie Member
I was converting old asp files to php.

But I'm stuck at this point.

I'm looking for a triple combo listboxes where one has "book" the other "chapter" and the third "verse". The book is populated by a database table. Once book is selected then chapter is populated and then verse.

Any tutorial related to this?
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Seems like we don't have such an article here yet. You can either use AJAX, or submit the form on combo box change to achieve your objective. Try it out....and do let us know if you are stuck!
Mirey86's Avatar, Join Date: May 2008
Newbie Member
PHP isn't exactly capable of what you are trying to do.

ASP <---> Client
PHP ---> Client

You could get around this by creating JavaScript arrays and looping through them when the user clicks a book and populate the listbox that way.

Eg.
User loads page... Every book is loaded, alongside the book's chapters and verses for every chapter, they are all stored in JavaScript array... The user clicks a book, in the onchange event for the listbox, use JavaScript to loop through the appropriate array using the foreach() method... Then add nodes to the next listbox...

The above method is inefficient but it should work.

If that doesn't take your fancy, perhaps frames? and using the JavaScript onchange event to modify the url of the next frame. The url may contain $_GET data (Eg. You load the url: mysite.com/getchapters.php?bookid=34) then you can use PHP to fetch all the chapters in the book.

I hope I helped you.

Mirey
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Quote:
Originally Posted by Mirey86
PHP isn't exactly capable of what you are trying to do.

ASP <---> Client
PHP ---> Client

You could get around this by creating JavaScript arrays and looping through them when the user clicks a book and populate the listbox that way.

Eg.
User loads page... Every book is loaded, alongside the book's chapters and verses for every chapter, they are all stored in JavaScript array... The user clicks a book, in the onchange event for the listbox, use JavaScript to loop through the appropriate array using the foreach() method... Then add nodes to the next listbox...

The above method is inefficient but it should work.

If that doesn't take your fancy, perhaps frames? and using the JavaScript onchange event to modify the url of the next frame. The url may contain $_GET data (Eg. You load the url: mysite.com/getchapters.php?bookid=34) then you can use PHP to fetch all the chapters in the book.

I hope I helped you.

Mirey
What do you mean by
Code:
 ASP <---> Client
 PHP ---> Client
@Richlife:

How did your ASP implement this feature?