#1
  1. No Profile Picture
    raghuram
    Guest
    Devshed Newbie (0 - 499 posts)
    Hi All

    I'm new to PHP/MySQL. I'm using two pages in my project. One for Inserting the profile of
    the users and other for updating the profile.

    I've a SELECT OPTION MULTIPLE tag in my insert.php3.

    <select name="busstype" multiple size="4">
    <option value="Importer">Importer</option>
    <option value="Exporter">Exporter</option>
    <option value="Manufacturer">Manufacturer</option>
    <option value="Supplier">Supplier</option>
    </select>

    The User can select as per his wish. I'm inserting all the selected values into the
    database in a single field, the values are seperated by a delimiter comma(","). For eg.

    Suppose the user selects Importer, Exporter and Supplier, it will be stored as
    Importer,Exporter,Supplier for the particular user.

    Upto this it works fine for me.

    Going to Update page (update.php3), i'm able to display all the TEXT field values. also i
    want to display the SELECT OPTION MULTIPLE tag. I can split the values using split()
    function ( split(",",myrow["busstype"]) ).

    now i want to display the page to the user for updation with Importer, Exporter and
    Supplier SELECTED and the Manufacturer not selected.

    can anyone recommend me how to do this.

    Thanks in Advance
    Raghu.
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15


    Here is the script which you are looking for.

    just modify this script as per you requirment.

    <?php
    $drop_down_values=array(Importers,Exporters,Manufacturers,Suppliers);
    //First create an array with all the items of drop down menu.

    $con=mysql_connect("localhost","username","password");
    // connectivity string.

    mysql_select_db("databasename",$con);
    //select database
    $result=mysql_query("select category from tblname where some conditions ",$con);
    // pass a query to mysql.

    $row=mysql_fetch_array($result);
    //get the row values.

    $pieces = explode (",", $row["category"]);
    //separate the Item values.

    $drop_count=count($drop_down_values);
    //take the total count of dropdown items.

    $piece_count=count($pieces);
    //count of selected items, which we fetched from database.

    echo "<select size="5" name=" category " multiple>n";

    for($a=0;$a<$drop_count;$a++){
    //loop for populating selected values to the drop down.

    $repeat="0";
    //don't match the value more than once..

    for($b=0;$b<$piece_count;$b++){
    //loop for matching the selected item
    if ("$drop_down_values[$a]"=="$pieces[$b]"){
    // selected item matching with drop down item
    //make it as selected.
    echo "<option selected value="$drop_down_values[$a]">$drop_down_values[$a]</option>n";
    $repeat="1";
    //this value is matching, and already made it as selected.
    //so donít match this value again.
    }
    }

    if ($repeat=="0"){
    //No matching for drop down item...
    echo "<option value="$drop_down_values[$a]">$drop_down_values[$a]</option>n";
    }
    }

    echo "</select>n";
    //close the drop down.

    ?>

    You can optimize this script.
    let me know the result.

    Good Luck!!


    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    raghuram
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks Shiju. The Code is working fine.

Similar Threads

  1. Updating text fields from dynamic SQL select box?
    By Trent Hatred in forum HTML Programming
    Replies: 3
    Last Post: February 6th, 2004, 10:34 AM
  2. New Select box option (C#)
    By WisconsinGuy in forum .Net Development
    Replies: 1
    Last Post: February 5th, 2004, 09:40 AM
  3. Naming a SELECT box with setAttribute() issue
    By vbrtrmn in forum HTML Programming
    Replies: 1
    Last Post: January 15th, 2004, 01:21 PM
  4. displaying mysql result in a select box
    By notaloser in forum PHP Development
    Replies: 4
    Last Post: January 13th, 2004, 05:30 PM
  5. Access: list box/combo box "After Update" problems
    By hlove in forum Database Management
    Replies: 2
    Last Post: January 2nd, 2004, 01:22 AM

IMN logo majestic logo threadwatch logo seochat tools logo