SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Retrieving multiple results

    I feel dumb asking this, but I've never had to do it before.

    I have a multiple select box in a form. How do I get the results for them, and run a sql query based on each one selected?

  2. #2
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you haven't done so already, you'll need to name the <select> in such a way that it'll result in an PHP array:
    HTML Code:
    <select name="cities[]" multiple="multiple">
      <option>A</option>
      <option>B</option>
    </select>
    And you'll get an array in PHP called $cities when someone submits the form.

  3. #3
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have created the form. When I get the array how do I run the query based on it?
    PHP Code:
    while ($cities)
    {
       
    execute query


  4. #4
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does your query look like?

  5. #5
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am entering one query that puts the ticekt into the database. Then my second query which will run from the while loop will put into a second database all the issues that ticket has assigned to it. So it would be something like this.

    PHP Code:
    while ($issue_type)
    {
      
    $sql "INSERT INTO fsi (issue_type, ticket_id) VALUES('$issue_type', '$ticket_id')";
      
    $result mysql_query($sql) or die (mysql_error());


  6. #6
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I understand it correctly:
    PHP Code:
    foreach ($issue_type as $it)
    {
      
    $sql "INSERT INTO fsi (issue_type, ticket_id) VALUES('$it', '$ticket_id')";
      
    $result mysql_query($sql) or die (mysql_error());


  7. #7
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, so I would use a for loop. All I've used previously is while loops. I guess I don't quite understand what the benefits of each one would be.


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
  •