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

  • Home
  • SEARCH
  • 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 9089395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:08:21+00:00 2026-06-16T22:08:21+00:00

I have a PHP form that shows data from a MySQL table. Each row

  • 0

I have a PHP form that shows data from a MySQL table. Each row obviously has different data, what I want to do is have a drop down list that displays data relevant to the data entry in each row.

for example, lets say I have two tables. Fruit and Fruit_Colors, as below:

enter image description here
enter image description here

so if my PHP Form was displayed as below, the MySQL data named fruits would display the data in the Fruit column. The color would then be fetched from the Fruit_Colors table depending on the PHP form output value in field ‘Fruit’. so the drop down list for each row will be different.

enter image description here

my PHP form table syntax is:

<table id="hor-minimalist-a">
    <tr>
        <th>ID</th>
        <th>Fruit</th>
        <th>Color</th>
        </tr>
<? while($row = $fruits->fetch(PDO::FETCH_ASSOC)) { ?>
    <tr>
        <td><? echo $row['id']; ?></td>
        <td><? echo $row['fruit']; ?></td>
        <td><SELECT NAME="fruitcolor" id="fruitcolor">
            <OPTION VALUE=0 >
             *// what goes here???*
            </option>
            </SELECT> 
        </td>
    </tr>
<? } ?>
</table>

Any advice how I can complete this would be appreciated. remember this table could be up to 50 rows so need a dynamic way of passing the ‘fruit’ value to the drop down list.

Syntax I know for the drop down list populations is:

    function fruitcolor_dropdown($db)  
  {    
    $result = $db->query("select color from Fruit_Color where Fruit=*'outputted value'*"); 
    return $result; 
  } 
  $colors= fruitcolor_dropdown($db); 
  while($row = $colors->fetch(PDO::FETCH_ASSOC)) {
  $color=$row["color"];
  $optionsfruitcolors.="<OPTION VALUE=\"$color\">".$color; 
  }

Advice appreciated as always. Thanks and Regards.

  • 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-16T22:08:22+00:00Added an answer on June 16, 2026 at 10:08 pm

    It will be bad idea to connect and fire query two time when you can do it in single query-
    you can see demo

    $query = "select f.*,group_concat(color SEPARATOR '|') as fcolor from fruit F Left join fruit_color fc using (fruit) group by fc.fruit";
    

    Above will be your query and you will loop it like below:

    <? while($row = $fruits->fetch(PDO::FETCH_ASSOC)) { ?>
        <tr>
            <td><? echo $row['id']; ?></td>
            <td><? echo $row['fruit']; ?></td>
            <td><SELECT NAME="fruitcolor" id="fruitcolor">
                <OPTION VALUE=0 >
                 <?php 
                   $array = explode("|", $fcolor);
                   $count = count($array);
                   for($loop=0;$loop<$count;$loop) {
                     echo "<option>".$array[$loop]."</option>";
                   }                                       
                  ?>
                </option>
                </SELECT> 
            </td>
        </tr>
    <? } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form that I am passing data from to a php
I have an array of data that I'm getting from this form (form.php): <?
I have an html table that pulls data from a DB. It has an
I have a table that displays data from a MySQL table. I have an
I have a php form that has a known number of columns (ex. top
I currently have a PHP form that uses AJAX to connect to MySQL and
i have a PHP contact form that submits data, and an email...: <?php $dbh=mysql_connect
(Using MySQL and PHP) I have a search form that will allow my users
I have a simple form that inserts data in a table on my server.
I have a php form that saves the info to my database and sends

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.