Jump to content

Dynamically Populate a drop down box


ajannick

Recommended Posts

Hi,

 

I have a website with products for sale and along side each item I have displayed the number of each of these items that are left in stock.  What I want to do is to have a dropdown box so that the user can choose the qty of itmes to order but they should not be able to order more than what is in stock.

For example if there are 5 items left then the drop down box must be initialised at 0 and show the numbers 1,2,3,4,5.  When a purchase is made then the drop down must be adjusted to match what is left in the database.

<?php

  $link = mysql_connect("mysql", "name", "password");

  mysql_select_db("product");

 

  $query = "SELECT qty FROM product WHERE id='1'";

  $result = mysql_query($query);

         

            echo "<select name=\"Qty\">";

            echo "<option selected>0</option>";

 

 

  while ($line = mysql_fetch_array($result))

  {

                echo "<option>".    ???????    ."</option>";

          }

 

    mysql_free_result($result);

    mysql_close($link);

?>

        </select>

 

I have thought about may be a for loop displaying numbers from 1 to the amount left in the database but not sure how to go about it.

 

Any help would be most appreciated.

 

N.

Link to comment
https://forums.phpfreaks.com/topic/53827-dynamically-populate-a-drop-down-box/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.