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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:41:33+00:00 2026-06-09T08:41:33+00:00

Let me try this again so I would like for my dropdown menu to

  • 0

Let me try this again so I would like for my dropdown menu to be in the row with the data that it pulls. Then able to add more rows if needed.

So in essence I would like to choose an item, it display the item’s properties on the same row. Then add more rows with a click of a button.

The table would look like this:

example

This is what I have so far:

HTML:

 <div id='main'>
              <!--Dropdown Will not work inside of table-->
         <select id='ddName' onchange="showUser(this.value)"> 
                <option id='none'>Select a Food:</option>
                <?php $sql = new Mysql(); $sql->diary(); ?>
                </select>
         <input type='button' id='addRows' value='Add Rows'/> 
        <table id="diary">
        <thead>
            <tr>
                <th scope="cols">Check</th>
                <th scope="cols">Name</th>
                <th scope="cols">Units</th>
                <th scope="cols">Amounts</th>
                <th scope="cols">Calories</th>
                <th scope="cols">Sugars</th>
            </tr>
            </thead>
            <tbody>
               <tr id='txtHint'></tr>
            </tbody>
            </table>
    </div>  

Ajax for dropdown:

//Retrived from w3schools.com
function showUser(str)
    {
    if (str=="")
      {
      document.getElementById("txtHint").innerHTML="";
      return;
      } 
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","classes/ajax.php?q="+str,true);
    xmlhttp.send();
    }        

PHP for filling the table:

//Retrived from w3school.com 
$q=$_GET["q"];

require_once dirname(dirname(__FILE__)).'/includes/constants.php';

$con = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or 
                  die('There was a problem connecting to the database.');

$result = $con->query("SELECT * FROM ingredient WHERE name = '".$q."'");


while($row = $result->fetch_array())
 {
   echo "<td><input type='checkbox' /></td>";
   echo "<td>".$row['Name']."</td>";
   echo "<td>" . $row['Units'] . "</td>";
   echo "<td>" . $row['Amount'] . "</td>";
   echo "<td>" . $row['Calories'] . "</td>";
   echo "<td>" . $row['Sugar'] . "</td>";
   echo "</tr>";
 }
  • 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-09T08:41:34+00:00Added an answer on June 9, 2026 at 8:41 am

    I was able to figure out my problem. I combined the two php codes into this one.

    PHP Fix:

    $q=$_GET["q"];
    
    require_once dirname(dirname(__FILE__)).'/includes/constants.php';
    
    $con = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or 
                      die('There was a problem connecting to the database.');
    
    $result = $con->query("SELECT * FROM ingredient WHERE Name = '".$q."'");
    $dd     = $con->query("SELECT * FROM ingredient");
    
    if($q == 'Select a Food:')
    {
       echo "<td><input type='checkbox' /></td>";
       echo "<td><select id='ddName' onchange='showUser(this.value)'>";
       echo "<option id='none'>Select a Food:</option>";
       while($ddrow = $dd->fetch_assoc())
         {
           if($ddrow['Name'] != $q)
              {
                echo "<option value='".$ddrow['Name']."'>".$ddrow['Name']."</option>";
              }
           else
              {
                echo "<option value='".$ddrow['Name']."' selected='selected'>".$ddrow['Name']."</option>";
              }
         }
       echo "</select></td>\n";
       echo "<td></td>";
       echo "<td></td>";
       echo "<td></td>";
       echo "<td></td>";
       echo "</tr>";
    }
    
    else{
    
     while($row = $result->fetch_array())
       {
        echo "<td><input type='checkbox' /></td>";
        echo "<td><select id='ddName' onchange='showUser(this.value)'>";
        echo "<option id='none'>Select a Food:</option>";
            while($ddrow = $dd->fetch_assoc())
         {
          if($ddrow['Name'] != $q)
          {
            echo "<option value='".$ddrow['Name']."'>".$ddrow['Name']."  </option>";
          }
          else
          {
              echo "<option value='".$ddrow['Name']."' selected='selected'>".$ddrow['Name']."</option>";
          }
        }
          echo "</select></td>\n";
          echo "<td>" . $row['Units'] . "</td>";
          echo "<td>" . $row['Amount'] . "</td>";
          echo "<td>" . $row['Calories'] . "</td>";
          echo "<td>" . $row['Sugar'] . "</td>";
          echo "</tr>";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so let me try to explain this the best way that i can.
EDIT : Let's try this again. This time I've used the AdventureWorks sample database
I understand my question is not that clear so let me try explaining it
Alright so I have a task, that I have to let the client try
I try to implement a browser-like app. I want to let it can open
I would like to estimate the initial cost that I would need to afford
I would like to have an advice for this issue: I am using Jbos
I would like to implement a producer/consumer scenario that obeys interfaces that are roughly:
at first I would like to try to explain my plan: Sometimes I just
If you do a join that looks like this SELECT T1.KeyField1, T1.KeyField2, T2.Field3 FROM

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.