...

View Full Version : retieve values of mutiple select box



esthera
03-11-2007, 03:27 PM
i have a multiple select box

how in php do i retrieve the values and loop through the values

(i have to add a record in the db for each one)

also I need to get the id of the first record put in
(I am adding a member and then a correlating set of schools (a separate table with schoolid,memberid) -- so how do i get the member id of the last inserted record to put in the member_school table)


thanks

Fou-Lu
03-11-2007, 09:31 PM
To create a multple select, throw the html with an array:


<select name="schools" multiple size=5>
<option value="school1">School 1</option>
<option value="school2">School 2</option>
<option value="school3">School 3</option>
...
<option value="schooln">School n</option>
</select>

This should return an array of schools for anything that has been selected. Off hand as well, I cannot recall if it will return an empty array or null in the instance of no selections, so you may need to ensure the existance of $_REQUEST['schools'] before processing data.

To fetch the last inserted record in mysql use mysql_insert_id. Now, this may not be practical for your solutions depending on your operation. Instead, you may want to fetch the value of the last value using a query to retrieve the last value in the table and use that. You could also add it to your html form with a hidden input value.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum