Forums

This topic is locked

how to make a dropDown List with some values

Posted 08 Oct 2002 07:38:52
1
has voted
08 Oct 2002 07:38:52 Manou Manou posted:
Hi;
I am trying to make a database driven webpage, I am newbie on PHP/
Mysql and use DWMX,
I have made a simple database containing 11 tables,
One category table and 10 others are detail of my database as follows:
Category table: category_id, category,
Company table: company_id, company, category_id.
Phone table: phone_id, phone, company_id
Fax table: fax_id, faxNo, company_id

And so on for the rest of the tables,
I have made relationship between "company_id" column in the company
tables and other 9 table's "company_id" column, and relationship
between "category_id" column in the company table and "category_Id"
column in category table.
I want to have a drop down list menu on my page but I don't know how
to do it, that when you click on one category, a page opens up with
the respective data on it,I am not sure what the value should be in,
I appreciate any help on this.
Thanx.

Replies

Replied 08 Oct 2002 19:28:47
08 Oct 2002 19:28:47 Ned Frankly replied:
A few steps (all of this is in the tutorials, but putting it together can be tricky):

Create the Detail Page (the page that will be shown when the dropdown is selected). The trick here is to make it so it will provide the correct data with a minimum of passed fields. You have complicated things slightly by having the same field names in multiple tables - MySQL makes you be VERY specific in your queries if you do this. From your example, CompanyID is the common field, so your query will look something like:

SELECT Category.category_id, category, Company.company_id, Company.company, Company.category_id AS CompanyCatID, Phone.phone_id, Phone.phone, Phone.company_id AS PhoneCompanyID, fax_id, faxNo, Fax.company_id AS FaxCompanyID
WHERE Company.company_id = varCompanyID AND Company.category_id = Category.category_id AND Phone.company_id = Company.company_id AND Fax.company_id = Company.company_id

Variable Definition:
varCompanyID default=0 runtime=Request.QueryString("ItemID"

This query is NOT tested, it's off the top of my head - check my syntax. You actually don't need any of the fields that are 'renamed', but I included them for clarity. They can be left of of the select statement if you want. Also, this will only show records where all of the tables contribute (a missing fax entry, for example, means the whole record will be missing). If this is a problem, you will have to use 'LEFT JOIN'.


This is now a recordset that allows input from Request.QueryString();
Test it by manually entering data in your browser i.e.: detail.asp?ItemID=3
You now have a destination page for your dropdown.

On the 'calling' page:
Create a recordset with your desired dropdown data (CompanyID)
Create a form (we'll call it form1) with a method of GET and an action of your detail page (created above)
Create a dropdown and name it something like 'ItemID'
Click the dropdown, look at Properties (CTRL-F3) and click the Dynamic button.
Select the recordset you created above.
For LABELS select the 'name' field, whatever you called it.
For VALUES select the RecordID field, whatever you called it.
Click OK.
Add an 'onChange' event to the select statement to submit your form i.e.:
<select name='ItemID' onChange="document.form1.submit()">. If you use a real submit button, this is not necessary. It's good practice to use a submit button anyway (even if you are auto-submitting) in case someone has scripting blocked, or they backed into the page.

Now when someone changes the value in your dropdown, the form will submit and go to your detail page, passing the appropriate record number to display the desired data. If our query above was correct, you should be quite happy.

Ned Frankly
Replied 09 Oct 2002 05:35:25
09 Oct 2002 05:35:25 Manou Manou replied:
Thank you Ned, it is great, I am going to try that,
Thank you again.

Reply to this topic