Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    May 2004
    Thanked 0 Times in 0 Posts

    retieve values of mutiple select box

    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)


  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,662 Times in 2,631 Posts
    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>
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts