Loading values in drop down dynamically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpmagesh
    New Member
    • Nov 2008
    • 119

    Loading values in drop down dynamically

    Hi,

    I have a drop down in my page, what i will do with that drop down is i have a table in my database, which have values and this table will refer that ID and pick the name of that values and display in the drop down box.

    my table have ID, name, quantity, stock and date created. now what i want to do is when

    the stock is <=0 the drop down should add sold out in front of the attributes.

    Ex:

    my drop down box is like this:

    Code:
    <select name="sample" id="sample">
    <option value="34">Apple</option>
    <option value="35">orange</option>
    <option value="36">graphs</option>
    <option value="37">mango</option>
    </select>
    when the customer comes and purchase some fruits from here

    Ex :

    i have apple - 2, orange - 1, graphs - 3, mango - 5.

    when customer orders orange and orange is sold out. then it will will automatically come to 0 (zero) in database. [stock = 0]

    what i want to do is when stock is 0 i should show the sold out message with that attribute like:

    Code:
    <select name="sample" id="sample">
    <option value="34">Apple</option>
    <option value="35">sold out - orange</option>
    <option value="36">graphs</option>
    <option value="37">mango</option>
    </select>
    I tried this but every time i refresh my page one sold out word is adding in the drop down list.

    what method i can go with this, i need some solution or idea to do this, can any one help me in this please.

    I need to know whether i m clear with my point??

    Thanks in advance

    Regards
    magesh
    Last edited by ak1dnar; Jan 19 '09, 09:38 AM. Reason: Added code tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by phpmagesh
    I tried this but every time i refresh my page one sold out word is adding in the drop down list.
    what is the code causing this?

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      I would approach this in the following steps:

      1. get the data for the dropdown including the current stock figure
      2. loop through the results creating the dropdown with code, before adding in the display test the stock, if stock is 0 the prefix description with 'Sold Out' otherwise use as is.

      This leaves all the descriptions in the original state in the database, is dynamic so when stock changes the drop down will be changed.

      If that idea doesn't help I refer you to the post from Dormilich - what is the code causing this issue.

      Cheers
      nathj

      Comment

      • phpmagesh
        New Member
        • Nov 2008
        • 119

        #4
        Originally posted by nathj
        I would approach this in the following steps:

        1. get the data for the dropdown including the current stock figure
        2. loop through the results creating the dropdown with code, before adding in the display test the stock, if stock is 0 the prefix description with 'Sold Out' otherwise use as is.

        This leaves all the descriptions in the original state in the database, is dynamic so when stock changes the drop down will be changed.

        If that idea doesn't help I refer you to the post from Dormilich - what is the code causing this issue.

        Cheers
        nathj
        Hi,

        Thanks for your reply, i worked with it and i got the solution.

        what i did is i just checked the stock value inside the loop like:

        Code:
        <select id="" name="">
        {foreach loop  } 
        if (stock_item =='0')
        {
        <option value ="34">Sold out - Apple </option>
        }
        else
        {
        <option value ="34">Apple </option>
        }
        </select>
        if if stock is 0 then the first loop is executed and if not this will execute the second loop.

        thankyou for you all.

        Regards
        magesh
        Last edited by Markus; Jan 22 '09, 12:28 PM. Reason: added [code] tags. phpmagesh, please view your PMs.

        Comment

        Working...