Data from MySQL into an PHP dropdown box


I am having trouble getting all data from MySQL database table into a drop-down form.

I have a table in a database that has four columns like this this example:
Products table:
Salesman id – which is a foreign key
Product id – which is a foreign key
Date –timestamp

I am trying to build an insert, edit and delete form in PHP. I want to be able to connect to the database table and have the salesman id and the product id update in an html drop-down box. So if there are nine salesmen with an id of 1 through 9. I want to be able to click on the selection tab and choose which nine salesman id I want - same for the product id. One salesman can have different product ids attached to them. I know in phpMyAdmin you can select a table and click on insert and see the Value dropdown button with all the nine salesmen to insert. When I try to code to get all the salesman ids I only get eight. I am not sure what I am missing. If someone can help me I appreciate it.

Here is my code I have so far.
This code will only display eight of the nine salesman ids – I need all nine. I need to do the same for product id.


    $query = "select DISTINCT salesmanid from products";
 $result = $db->query($query);
   $numrecs = $result->num_rows;
echo '<select name = "salesmanid">';
echo "Select an option</option>";
 for ($i = 0; $i < $numrecs; $i++ )  {
$row = $result->fetch_assoc();
echo '<option value ="'.$row[' salesmanid '].'">'.$row[' salesmanid '].'</option>';
 echo '</select>';



Something, similar or exactly to this should get you going.

[php] $query = “select DISTINCT salesmanid from products”;
$result = $db->query($query);
$numrecs = $result->num_rows;
echo ‘’;
echo “Select an option”;

while($row = $result->fetch_assoc()) {

echo ‘’.$row[’ salesmanid ‘].’’;


echo ‘’;[/php]



Thanks for your reply. I appreciate your code. I figured it out. I was pulling from the wrong table. I got my code to work.

Thank you.