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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:14:39+00:00 2026-06-09T03:14:39+00:00

After reading and finding online, I still do not have any idea how to

  • 0

After reading and finding online, I still do not have any idea how to solve my problem. And there’s no way that I can do like this:

$select=mysql_query("select * from products_list categories where id='3'");
while($row=mysql_fetch_array($select)){

echo "whatever fields that I want to display onto the form before category field";

$select=mysql_query("select * from categories ORDER BY id ASC");
while($row=mysql_fetch_array($select)){

echo "compare with the result in categories table and select the option if it's true";

}
}

Am I right?

Currently I have 2 tables in database products_list and categories.

Table products_list consist of many fields:
ID, code, price, category, status, etc…

Table categories only have:
ID, category (where this table only contains all the available set of category options)

I have an update/edit form which I use the select statement and get all the results from Table products_list that the user previously saved all their data.

Under the category part on the form itself is a multiple selection listbox.

My problem now is:

  1. Display all the result from Table products_list onto the update/edit form
  2. Display all the category options from Table categories onto the update/edit form (listbox)
  3. Comparing the category that is saved by the user in Table products_list and select the options that is display on the listbox (which is no.2 question)

I really need a lot of help on this as I have never done this before and don’t know what’s going on reading those articles or threads online. Hope you guys understand my question. Thanks in advance.

Currently updated codings but still stuck:

$result2= mysql_query("SELECT category FROM categories ORDER BY id ");
$all_cat = array();
while($row2 = mysql_fetch_assoc($result2)) { 
    $all_cat[] = $row2['category'];
}

//dropdownlist query
$query="SELECT * from products_list where id='100'";
$result = mysql_query ($query);

//populate the dropdownlist

while($row = mysql_fetch_assoc($result)) { 

  $sel_cats = explode(",", $row['category']);
  //determine if the category is selected
  foreach ($sel_cats as $sel_cat){

  $selected = '';

  if ($sel_cat == $all_cat ){
           $selected =' selected="selected" ';
           break;
        }

  }

    foreach($all_cat as $i => $value)
    {
     echo  '<option value="' . $value. '"' . $selected . '>'.$value.'</option>\n';
    }

}
  • 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-09T03:14:41+00:00Added an answer on June 9, 2026 at 3:14 am
    // get all product, assuming the saved category is cat column in product_list table
    $result2= mysql_query("SELECT * from products_list where id='3'");
    $row2 = mysql_fetch_assoc($result2);
    $sel_cat =$row2['cat'];
    
    //dropdownlist query
    $query="SELECT cat,id FROM categories ORDER BY id ";
    $result = mysql_query ($query);
    
    
    //populate the dropdownlist
    while($row = mysql_fetch_assoc($result)) { 
          //determine if the category is selected
          $selected = ($row['id '] == $sel_cat ) ? ' selected="selected" ' : NULL;
          echo  '<option value="' . $row['id']. '"' . $selected . '>'.$row['cat'].'</option>\n';
    }
    

    For category saved in concatenated string format. eg: black,white,red

     // get all product, assuming the saved category is cat column in product_list table
        $result2= mysql_query("SELECT * from products_list where id='3'");
        $row2 = mysql_fetch_assoc($result2);
        $sel_cats = explode(',', $row2['cat']);
    
        //dropdownlist query
        $query="SELECT cat,id FROM categories ORDER BY id ";
        $result = mysql_query ($query);
    
    
        //populate the dropdownlist
        echo '<select name="cat" size="5" multiple="multiple">';
        while($row = mysql_fetch_assoc($result)) { 
              //loop thru the sel_cat
               foreach ($sel_cats as $sel_cat){
              //determine if the category is selected
               $selected = '';
               if ($row['id '] == $sel_cat ){
                   $selected =' selected="selected" ';
                   break;
               }
              }
              echo  '<option value="' . $row['id']. '"' . $selected . '>'.$row['cat'].'</option>\n';
    
        }
        echo '</select>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading MSDN-XAML Namespaces and MSDN-Understanding XAML Namespaces , I still do not understand
After reading a tutorial of Flash, I am still not sure what exactly is
after reading the cookbook and various Q&A here I am still a bit confused
After reading jQuery's CSS documentation , it doesn't look like it offers any advantages
After reading several articles of a hierarchical data tables, I've made my way into
I'm not experienced with java applications but I found out that finding static pointers
I have been reading up on triggers, and I don't seem to be finding
I'm new to Apache Solr. Even after reading the documentation part, I'm finding it
Is there a fast way to search for string in another string? I have
There are four high level APIs to access Cassandra and I do not have

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.