By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,915 Members | 1,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,915 IT Pros & Developers. It's quick & easy.

Loading values in drop down dynamically

100+
P: 119
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:

Expand|Select|Wrap|Line Numbers
  1. <select name="sample" id="sample">
  2. <option value="34">Apple</option>
  3. <option value="35">orange</option>
  4. <option value="36">graphs</option>
  5. <option value="37">mango</option>
  6. </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:

Expand|Select|Wrap|Line Numbers
  1. <select name="sample" id="sample">
  2. <option value="34">Apple</option>
  3. <option value="35">sold out - orange</option>
  4. <option value="36">graphs</option>
  5. <option value="37">mango</option>
  6. </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
Jan 19 '09 #1
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
@phpmagesh
what is the code causing this?
Jan 19 '09 #2

nathj
Expert 100+
P: 938
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
Jan 21 '09 #3

100+
P: 119
@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:

Expand|Select|Wrap|Line Numbers
  1. <select id="" name="">
  2. {foreach loop  } 
  3. if (stock_item =='0')
  4. {
  5. <option value ="34">Sold out - Apple </option>
  6. }
  7. else
  8. {
  9. <option value ="34">Apple </option>
  10. }
  11. </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
Jan 22 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.