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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:44:23+00:00 2026-05-28T02:44:23+00:00

I need some help please, I have a PHP page with a drop down

  • 0

I need some help please,

I have a PHP page with a drop down list, populated by a mysql database query.
I want to be able to display the database details for the selected option in the other table cells.
Ideally this can be acheived without a page refresh.

In addition to this the table will consist of up to 75 rows (pallets on the vehicle – this is for a sales tool) so need to acheive this with a a while statement or something. each row will have a selection box to choose a packcode.

my code with the drop down lists is below, the table only consists of the 5 rows for now.

I know I need to use ajax or javascript in addition to this?

If anyone has an example script or can use my code as an example I would really appreciated it.

<?

  $con = mysql_connect("localhost","user","password");
  if (!$con)
  {
    die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("dbname", $con);

  $packcodesql="SELECT packcode from skudata order by packcode"; 
  $resultpackcode=mysql_query($packcodesql); 
  $optionspackcode=""; 

  while ($row=mysql_fetch_array($resultpackcode)) { 
     $packcode=$row["packcode"]; 
     $optionspackcode.="<OPTION VALUE=\"$packcode\">".$packcode; 
  } 
?>

<table border=1>
<tr>
  <td>Pack Code</td>
  <td>Category</td>
  <td>Selling Units</td>        
  <td>Full Pallet QTY</td>
  <td>Order QTY</td>
</tr>
<Tr>
  <td>
    <SELECT NAME=packcode1 style="width:100px;"> 
        <OPTION VALUE=0><?=$optionspackcode?></SELECT> 
  </td>
  <td>
    <!-- show mysql result for "select Category from skudata where packcode=packcode1" -->
  </td>
  <td>
    <!-- show mysql result for "select SellingUnits from skudata where packcode=packcode1" -->
  </td>     
  <td>
    <!-- show mysql result for "select FullPalletQTY from skudata where packcode=packcode1" -->
  </td>
  <td><input type="text" id="qty" name="qty"></td>
</tr>       
<Tr>
  <td>
    <SELECT NAME=packcode2 style="width:100px;"> 
        <OPTION VALUE=0><?=$optionspackcode?></SELECT> 
  </td>
  <td>
    <!-- show mysql result for "select Category from skudata where packcode=packcode2" -->
  </td>
  <td>
   <!-- show mysql result for "select SellingUnits from skudata where packcode=packcode2" -->
  </td>     
  <td>
   <!-- show mysql result for "select FullPalletQTY from skudata where packcode=packcode2" -->
  </td>
  <td><input type="text" id="qty" name="qty"></td>
</tr>       
<Tr>
   <td>
    <SELECT NAME=packcode3 style="width:100px;"> 
        <OPTION VALUE=0><?=$optionspackcode?></SELECT> 
   </td>
   <td>
    <!-- show mysql result for "select Category from skudata where packcode=packcode3" -->
   </td>
   <td>
    <!-- show mysql result for "select SellingUnits from skudata where packcode=packcode3" -->
   </td>        
   <td>
    <!-- show mysql result for "select FullPalletQTY from skudata where packcode=packcode3" -->
   </td>
   <td><input type="text" id="qty" name="qty"></td>
</tr>       
<Tr>
   <td>
    <SELECT NAME=packcode4 style="width:100px;"> 
        <OPTION VALUE=0><?=$optionspackcode?></SELECT> 
   </td>
   <td>
    <!-- show mysql result for "select Category from skudata where packcode=packcode4" -->
   </td>
   <td>
   <!-- show mysql result for "select SellingUnits from skudata where packcode=packcode4" -->
   </td>        
   <td>
    <!-- show mysql result for "select FullPalletQTY from skudata where packcode=packcode4" -->
   </td>
   <td><input type="text" id="qty" name="qty"></td>
</tr>       
</table>
  • 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-05-28T02:44:23+00:00Added an answer on May 28, 2026 at 2:44 am

    You want to populate the with data from a database that is linked to the box above the td’s?

    If so, you could use AJAX yeah, and put an onclick (pretty sure that should do it) on the options of the select box.

    <select>
        <option onclick="myAjaxFunction(this);">Some name</option>
        <option onclick="myAjaxFunction(this);">Some other name</option>
    </select>
    

    then you would have to create the function myAjaxFunction which will contain you code for the Ajax request (http://api.jquery.com/jQuery.ajax/).
    Simple example could be:

    <script>
    function myAjaxFunction(elem) {
        $.ajax({
            url: 'target/file.php',
            success: function(response) {
                $("#target-td").html(response);
            }
        });
    }
    </script>
    

    And finally a .php file that you call with the AJAX, containing your database call. In the file you just echo out what you want to display.

    Ideally, you will do one call and return it all using json. An attribute

    dataType: 'json'
    

    can be added to the $.ajax() call, and you can use:

    echo json_encode($myContent);
    

    in PHP you json encode you php content (preferably in an array()).

    This should have pointed you in the way 🙂 please tell me if i need to be more specific, or provide better examples…

    UPDATE

    You could create unique id’s for each of the td’s you want to target. Then create

    <td>
        <select>
            <option onclick="firstPackCodeAjax('<?=$packcodeValue?>');" value="<?=$packcodeValue?>"><?=$packcodeValue?></option>
        </select>
    </td>
    <td id="categoryTd">
       <!-- show mysql result for "select Category from skudata where packcode=packcode1" -->
    </td>
    <td id="unitsTd">
        <!-- show mysql result for "select SellingUnits from skudata where packcode=packcode1" -->
    </td>     
    <td id="palletTd">
        <!-- show mysql result for "select FullPalletQTY from skudata where packcode=packcode1" -->
    </td>
    

    Then your AJAX function would be:

    <script>
    function firstPackCodeAjax(packCode) {
        $.ajax({
            url: 'target/file.php',
            data: {code: packCode},
            dataType: 'json',
            success: function(json) {
                $("#categoryTd").html(json.Category);
                $("#unitsTd").html(json.SellingUnits);
                $("#palletTd").html(json.FullPalletQTY);
            }
        });
    }
    </script>
    

    This expects the data output to be json, and in the format:

    [
        { "Category": "Fast cars" },
        { "SellingUnits": "9001" },
        { "FullPalletQTY": "9001" }
    ];
    

    You would then create a function for each select you want to pull AJAX in with. The target/file.php you’ll need to create yourself somewhere. Here you fetch the data and echo it out in json. Good luck 😉 Also, this could very easily be optimized, but thats for later…

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

Sidebar

Related Questions

I need some help creating a query for my mySQL database. I have recently
I need some help with a LINQ query in VB.Net, please. I have this
I'm very new to MySQL so I need some help please, I have a
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help about with Memcache. I have created a class and want to
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
I need some help with priviligies in centos I have a file in home/admin/public_html/generate.php
I am getting a little confused and need some help please. Take these two
I need some help! Please. I am trying to develop a very very simple
I need some with help with PowerShell, please. It should be pretty easy: I

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.