php mysql drop down list :'(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
peter011
Forum Newbie
Posts: 1
Joined: Sun Mar 04, 2012 8:16 am

php mysql drop down list :'(

Post 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.
Last edited by peter011 on Tue Mar 06, 2012 4:51 am, edited 1 time in total.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php mysql drop down list :'(

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php mysql drop down list :'(

Post 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?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php mysql drop down list :'(

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply