Page 1 of 1

php mysql drop down list :'(

Posted: Sun Mar 04, 2012 8:20 am
by peter011
I am trying to read my database from mysql. I have two fields author and books. I need the author field to be in the drop down list and then when I choose an author I need it to display below on the same page all of the books by that author in the database. I don't really know how to use php. I know how to connect the database to php but then I don't know how to get the author from the database to the drop down list and then I am not really sure how to display the books below.

Re: php mysql drop down list :'(

Posted: Sun Mar 04, 2012 3:21 pm
by social_experiment
The code pasted is to create the dropdown menu; paste the code you use to select the books by a specific author from the database.

Code: Select all

$sql="SELECT * FROM tb_lib1, tb_lib2 WHERE tb_lib1.Id = tb_lib2.Id"; 
If you don't use all the fields you shouldn't select *. Select only fields you are going to use.

Re: php mysql drop down list :'(

Posted: Sun Mar 04, 2012 9:00 pm
by Celauran
I can't help but think a select list is a bit of an unwieldy solution to this problem. Unless this bookstore caters to an exceptionally small niche market, you're going to have hundreds if not thousands of authors. Wouldn't a simple text input make more sense?

Re: php mysql drop down list :'(

Posted: Mon Mar 05, 2012 12:24 am
by social_experiment
Celauran wrote:Wouldn't a simple text input make more sense?
interesting point; one reason i can think of (for the list) is that visitors to the site could possibly not know the correct spelling of the author and some visual reminder might help them