![]() |
How to post Multiple values from one selection
I have a while loop that generates a select dropdown.
The dropdown displays the name of the object from a database table for the user to select. When selected that name gets posted to another table. PHP Code:
If this wan't a loop I would just use a hidden input field for that, but I'm not sure how to do that in the a loop. |
Short answer: don't.
Assuming that the id is the primary key of the wp_flr_planes, there is never any reason to carry the plane_name into a different table. You can simply join the records and look up the plane_name from the wp_flr_planes table. All you need to store is the primary key of the wp_flr_planes in order to look up any corresponding information. If this is a composite key, then you do require both to be provided as the option value. The only way to do this in a select control is by using a method that allows you to pass both of the keys. An array of the two serialized would allow you to pass it as the option value, and you can unserialize it on the receiving side. |
OK I think I understand (maybe) what you are saying. Just store the ID then query the ID from the other table using the ID I just posted.
How would you do that? Would it it be something like a foreach loop then check if the ID exists? Does that sound right? |
Yep, and nope. That would be a join:
Code:
SELECT wfp.plane_name, ynt.destinationIf you use INNODB database engine, then you can add constraints as well (that are enforced). So in the secondary table, you can specify that it's "planeid" must reference the id in the wp_flr_planes. If it doesn't exist, it will throw an error, and you can set up cascading for updates and deletes. |
On the other hand, if you really *MUST* pass all 3 values--or if, for example,you don't want to even use the DB on the next page--then you can do this:
Code:
while ($rows = mysql_fetch_assoc($plane_result)) { Code:
$item = $_POST["item"]; |
Quote:
|
Bring up the page in your browser.
Click on the VIEW menu of your browser. Click on the SOURCE or PAGE SOURCE menu item. Now you are looking at the HTML a the browser sees it. In that HTML, find the <select> and <option>s that this code is producing. Copy/paste that code here. |
Ummm...you do realize that my
Code:
$item = $_POST["item"];In your code, the <select> is <select name="plane"> so you would want to do Code:
$item = $_POST["plane"]; |
| All times are GMT +1. The time now is 01:33 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.