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 8806647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:10:35+00:00 2026-06-14T02:10:35+00:00

I have: $selectedItem = ‘100,200,300’; And mysql load: <select multiple=multiple name=product_id> <?php $query =

  • 0

I have:

$selectedItem = '100,200,300';

And mysql load:

<select multiple="multiple" name="product_id">
   <?php
   $query = mysql_query("SELECT * FROM products ORDER BY id");
   while($row = mysql_fetch_array($query)){
      echo '<option value="$row[id]">$name</option>';
   }
   ?>
</select>

And I need $selectedItem (three values) to be:

<option value="$row[id]" selected>$row[id]</option>

How can I do that? I just can’t find the solution when the selectedItem more than 1.

  • 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-14T02:10:36+00:00Added an answer on June 14, 2026 at 2:10 am

    You should make your $selectedItem variable an array (and name it plural since it can have multiple values; just my added preference =P):

    $selectedItems = array(100, 200, 300);
    

    Doing this, you’ll be able to check if the current row’s id is in the array or not (with in_array()) and then “select” that row:

    while($row = mysql_fetch_array($query)) {
        $selected = in_array($row['id'], $selectedItems) ? ' selected="selected"' : '';
        echo '<option value="' . $row[id] . '"' . $selected . '>' . $row['id'] . '</option>';
    }
    

    Alternatively, if you can’t “define” your list of selected items as an array and you will only have a comma-separated string, you can use explode() to turn it into an array:

    $selectedItems = explode(',', $selectedItem);
    

    This will split the $selectedItem variable by commas into an array stored into $selectedItems (usable with the above code).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that looks like so: SELECT Name, SUM(Price * Quantity) AS
I have a TabControl with templated content as below: <TabControl x:Name=Items SelectedItem={Binding ActiveItem} TabStripPlacement=Left
Currently, I have this: Random random = new random.Next(1, strings.Items.Count); strings.Select(); strings.SelectedItem = strings.Items[Convert.ToInt32(random)];
I have a ComboBox that has the SelectedItem bound to the ViewModel. <ComboBox SelectedItem={Binding
Possible Duplicate: WPF Listview Access to SelectedItem and subitems I have a listview defined
I want to build my own listView with selectedItem and Itemsource. I have started
How do I bind a view model property to the ListBox.SelectedItem property? I have
I have a WPF CombBox as follows: <ComboBox ItemsSource={Binding Source={StaticResource myList}} SelectedItem={Binding Path=mySelectedItem} />
I have this if condition, if (sendSMS(Convert.ToInt32(DLComportNo.SelectedItem.Text), TxtDriMob.Text, TxtCliDet.Text) && sendSMS(Convert.ToInt32(DLComportNo.SelectedItem.Text), TxtCliMob.Text, TxtDriDet.Text)) {
I have this code: typeof(ComboBox).GetProperty(SelectedItem).SetValue(comboBox1, , null); It is not working. Here is the

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.