#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    7
    Rep Power
    0
    Hi,
    I've got a multiple select drop down box that is populated by PHP with values from a mysql db. Now when I am editing records, the PHP shows which values have already been selected, now what I need to do is to be able to change these values but I can't!

    I can add values to it but can't get rid of them.

    Does anyone have a suggestion on this?

    Here is the code I'm using:
    ________select statement________
    <select name="cid[]" size="5" multiple>
    <?php
    $result_selected = mysql_query("select f.rid,f.cid,c.id,c.title from foodlookup f,category c where f.rid=$rid and c.id=f.cid;",$db);
    $myrow = mysql_fetch_array($result_selected);
    do {
    printf("t<option value="%s" selected>%sn",$myrow["id"],$myrow["title"]);
    } while ($myrow = mysql_fetch_array($result_selected));
    ?>
    <?php

    //query for displaying your user information.
    $result_master = mysql_query("select title,id, COUNT(rid) AS count FROM category LEFT JOIN foodlookup ON cid=id and rid=$rid GROUP BY id having count=0;",$db);
    $myrow = mysql_fetch_array($result_master);
    do{
    printf("t<option value="%s">%sn",$myrow["id"],$myrow["title"]);
    } while ($myrow = mysql_fetch_array($result_master));
    ?>
    </select>

    _______ends________
    I populate the select statement in two parts - one to find the selected values, and then the second part populates the ones that have not been selected. It may look a little cryptic but I was the only way I could get it to work!

    _______submit_______
    for ($i=0;$i<count($cid);$i++) {
    $sql2 = "INSERT INTO FoodLookup (rid,cid) VALUES ('$rid','$cid[$i]')";
    $result2 = mysql_query($sql2);
    }
    _______end_______
    this submit to the database command runs through the values submitted (as it is a multiple select) and inserting them all - it works fine.


    Any suggestions on this would be much appreciated

    Dr Gonzo
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    It's kind of hard to understand what you are asking for. Are there are items in the "selected" database, that you don't want to be selected once the script is complete? If you know what the values are, then you could just test for that value, and if it's true, either don't print out that <option> line, or just don't output the "selected" within that option...

    if ($myvar = true)
    {
    echo "<option value="$name"> $name </option>n";
    }
    else
    {
    echo "<option value="$name" selected> $name </option>n";
    }

    Don't know if that helps or not. if it doesn't, just spend my $0.02 on something nice.

    ---John Holmes
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    7
    Rep Power
    0
    Hi John,
    The select is part of a form that enters restaurant information and the select statement is used to pick what kind of cuisine is on offer there.

    So, If I enter a restaurant and say it offers Thai, Lao and Indonesian cuisine, then on the select I pick Thai, Lao and Indonesian and enter it - no probvlems - that all works.

    Now lets say a year from now, the restaurant changes hands and does Pizza instead. What I want to be able to do is bring up the record (which will appear with Thai, Lao and Indonesian slected) and de-select these and reselect Pizza.

    The problem, is, the script will let me add pizza, but I can't get it to delete records (any or all of them).

    I put in another <option> called "delete" which was supposed to let the user delete all foot category entries and start again, and I tested for it by the sql insert statement, but that wouldn't work!

    Do you see what my problem is??

    Dr Gonzo

Similar Threads

  1. Validating multiple SELECT drop downs... can't figure it!
    By Trent Hatred in forum HTML Programming
    Replies: 3
    Last Post: January 29th, 2004, 10:43 AM
  2. Replies: 2
    Last Post: January 27th, 2004, 03:34 PM
  3. Populate multiple drop down box dependant on selection
    By maunded in forum PHP Development
    Replies: 3
    Last Post: January 21st, 2004, 12:52 AM
  4. Replies: 3
    Last Post: January 21st, 2004, 12:05 AM
  5. retrieving data from a drop down box for modifying
    By swordfishy in forum PHP Development
    Replies: 0
    Last Post: January 18th, 2004, 08:07 PM

IMN logo majestic logo threadwatch logo seochat tools logo