Form with multiple db lookups

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
shags_j
Forum Newbie
Posts: 9
Joined: Sun Aug 22, 2010 9:55 pm

Form with multiple db lookups

Post by shags_j »

HI All,

Fairly new to PHP but am having a slight problem with a page. I have a form that has two <select> boxes. The values to be put into the boxes are stored in a database. The tables used are a many to many relationship.

I wanted the values in the second box to reflect the selection from the first box based on the join table for the m-m relationship. (Does this all make sense???).

I am fairly sure that javascript will be involved here but was hoping to avoid it (never learnt javascript). Can I just do this with PHP?

Cheers,

Shags
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Form with multiple db lookups

Post by yacahuma »

you can do it. It just you need to refresh the page to do it the code will be something like. This is far from working code. is just the basic idea


if (isset($_GET['sel1'])
{
//show sel2 based on sel1 value
$sql = 'SELECT * FROM TABLE WHERE data=$_GET['sel1']";

//create sel2 options with SQL

//display sel1

//display sel 2
}
else
{
//DISPLAY SEL 1
}
shags_j
Forum Newbie
Posts: 9
Joined: Sun Aug 22, 2010 9:55 pm

Re: Form with multiple db lookups

Post by shags_j »

Worked a treat. Thanks. Reload isn't that much of a big deal.
Post Reply