Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.