Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:57:00+00:00 2026-06-08T17:57:00+00:00

I need help in this and am very confusing thinking how to do this.

  • 0

I need help in this and am very confusing thinking how to do this.

I have a form, an update/edit form, inside it I have a multiple selected listbox.

In my database records:

ID Items
1  Apple
2  Banana
3  Orange
4  Pear
5  Starfruit

And whenever the user clicks on edit which brings them to this form where I have made the listbox highlighted according to their previous saved data.

When the user clicks update, the listbox in the update form will look like this:

<option selected>Apple</option> <-- highlighted
<option>Banana</option>
<option selected>Orange</option> <-- highlighted
<option>Pear</option>
<option selected>Starfruit</option> <-- highlighted

This is what the user will see according to their 1st chosen items which was saved previously.

Currently I’m doing hard coding it:

<?php
$select=mysql_query("select * from products_list where id='$id' "); 
while($row=mysql_fetch_array($select)){

$product_category = explode("\n", $row['category']);
$i=0;

    echo '<select name="product_category[]" id="category" size="9" multiple="multiple"><option value="Black" ';
if ($product_category[$i] == "Black" ){ echo 'selected="selected"'; $i++; }
echo '>Black</option><option value="White" ';
if ($product_category[$i] == "White" ){ echo 'selected="selected"'; $i++; }
echo '>Black</option><option value="Blue" ';
if ($product_category[$i] == "Blue" ){ echo 'selected="selected"'; $i++; }
echo '>Black</option>';
}
?>

And so on so forth. I only list a few. So I would like to ask is there a way that I can do this, if my listbox options are not hard coded?

Hope you guys understand. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:57:01+00:00Added an answer on June 8, 2026 at 5:57 pm

    I’m sorry if i misunderstood you and your code but I think this is what you want to do:

    <?php
    $select=mysql_query("select * from products_list where id='$id' ");
    
    // Insert the categories in an array in order
    $categories = array('Black', 'White', 'Blue', ...);
    
    while($row=mysql_fetch_array($select))
    {
        $product_category = explode("\n", $row['category']);
    
        echo '<select name="product_category[]" id="category" size="9" multiple="multiple">';
    
        foreach($product_category as $i=>$value)
        {
            echo '<option value="'.$categories[$i].'"';
    
            if($value == $categories[$i])
            {
                echo ' selected="selected"';
            }
    
            echo '>'.$categories[$i].'</option>';
        }
    
        echo '</select>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a very common but rarely solved topic. I seriously need some help
i need help with this. I'am using JQuery's Dynamic Form plug-in, it duplicates my
I really need help on this one. I am having a simple login form
I am new to android and need help on this. I have two views
I really need help this time - Joomla 2.5 and latest K2. I'm using
I need help finishing this statement. It is frustrating that two of the PHP
I really need help with this last part of my program. I need to
I Really need help in this ... I'm building an application where I need
Not exactly about programming, but I need help with this. I'm running a development
Sorry to bother again, but I really need help transforming this Python2 code into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.