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

    I'm using a SELECT OPTION MULTIPLE tag in my html page. I've selected many values and inserted into the database successfully. The values that are in the database are seperated by the delimiter ','.

    Now i'm retrieving the data from the database. I want the values to be displayed as it was selected from the SELECT OPTION MULTIPLE tag. The values which i've selected previously to insert into the table should only be selected in the SELECT OPTION MULTIPLE tag.

    Can anyone recommend me how to do this.

    Thanx in Adv.
    Raghu.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    63
    Rep Power
    15
    Here's an example that should work fine... it tests out just right. With a little modification, you can get it to work through a loop so you only have to write it once.

    <?
    $selectstring="orange";
    ?>
    <option value=orange <?if(strpos($selectstring,"orange")!=-1){ print("SELECTED");} ;?>>I like oranges</option>
  4. #3
  5. No Profile Picture
    raghuram
    Guest
    Devshed Newbie (0 - 499 posts)
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by ujludwig:
    [B]This works good for SELECT OPTION tag. But i've a problem working the same code in SELECT OPTION MULTIPLE tag.

    Even i didn't give any string in the strpos() function for comparison, i'm getting all the values selected in the tag.

    Can u recommend me how to do this?

    TA
    Raghu.

    B][/quote]

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    63
    Rep Power
    15
    Can you show a little bit of the code that you used?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    This example may help if all option values are unique

    <?

    $chosen="apple,orange,pear"; // delimited string pulled from db

    $options=array("apple", "grapes", "orange", "lemon", "pear");

    print"<form method="post" action="foo">";
    print"<select name="test" multiple size=5>";
    while(list($key, $val)=each($options))
    {
    if(ereg($val, $chosen))
    print"<option value="$key" selected>$val";
    else
    print"<option value="$key">$val";
    }
    print"</select>";

    print"</form>";

    ?>

    The $options array, of course, may also be an associative array and generated from the database, depending on your needs.

    Later

Similar Threads

  1. Mailing List Scenario Advice
    By INF in forum Business Help
    Replies: 0
    Last Post: January 15th, 2004, 12:39 AM
  2. Coldfusion + Access 2002 scenario
    By jag5311 in forum Database Management
    Replies: 1
    Last Post: September 21st, 2003, 07:59 PM
  3. Replies: 3
    Last Post: September 20th, 2003, 10:48 PM
  4. Is this scenario possible
    By jjanes in forum Perl Programming
    Replies: 2
    Last Post: March 19th, 2003, 03:00 PM
  5. LOCK TABLES - and "ALTER TABLE" Scenario
    By Robert_J_Sherman in forum MySQL Help
    Replies: 2
    Last Post: October 31st, 2001, 09:02 AM

IMN logo majestic logo threadwatch logo seochat tools logo