SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Freo
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to submit multiple values using a listbox

    Hello
    Can any one tell me how to submit multiple values from a list box? I believe it has something to do with Arrays or Loops but i'm not sure.

    this is this list box code. As you can see it is populated by the products database.

    Could somebody show me what the array loop thing is supposed to look like. So this list box submits multiple values.

    <select name="vehicle_type" size="20" multiple>
    <?php do { ?>
    <option value="<?php echo $row_rsProducts['vehicle_type']?>" ><?php echo $row_rsProducts['vehicle_type']?></option>
    <?php } while ($row_rsProducts = mysql_fetch_assoc($rsProducts)); ?></select>

    much appreciated

    Thank you :0)

  2. #2
    SitePoint Member
    Join Date
    Mar 2005
    Location
    RUSSIA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    name of the select should be array:
    <select name="vehicle_type[]" size="20" multiple>

  3. #3
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Freo
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that Cmepeo but like anything you think you've solved it and another problem pop ups.

    After adding the [] to make it an array when I submit to the database it Enters a value of "Array" instead of the text for the list box

    the databse field is Text is this the reason why its submitting Array? Do I need to setup the database table differently?
    Last edited by dennis_doug; Mar 4, 2005 at 23:19.

  4. #4
    SitePoint Member
    Join Date
    Mar 2005
    Location
    RUSSIA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you want to store an array to a text field, just use

    serialize() - to convert the data to a string. then unserialize() to convert string to array.

    another method - make a string yourself by looping through the array, like this:

    item one;item two; array item three

    or something like this. then you can store it in the DB.


Bookmarks

Posting Permissions

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