943,559 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2071
  • PHP RSS
Sep 21st, 2009
0

Getting Explode Array into cart

Expand Post »
Hi , I am using an explode function to split some comma separated colors into a drop down list.

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. // Split the string up into an array of values
  4. $dropdown_data = explode(",", $row_rsApparel['Item_Colors']);
  5.  
  6.  
  7. // Output a dropdown
  8. echo '<select name="color" id = "color">';
  9. foreach($dropdown_data as $key => $value) {
  10. echo '<option value="'.$key.'">'.$value.'</option>';
  11. }
  12. echo '</select>';
  13. ?>

The drop down works perfectly but I can't seem to get that info into the cart. If I use a standard drop down list in dreamweaver, no problem binding that to the cart. Just not sure how to bind the selection from a php generated list into the cart?

any help would surely be appreciated.

thanks nigel
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nigelsponge is offline Offline
14 posts
since Sep 2009
Sep 21st, 2009
-1

Re: Getting Explode Array into cart

You use the $_POST array variable in your form handling routine to get the select value, namely $_POST['color'] in your case. Once you get this, simply use it in your update/insert SQL query.
Sponsor
Featured Poster
Reputation Points: 1046
Solved Threads: 942
Sarcastic Poster
ardav is offline Offline
6,661 posts
since Oct 2006
Sep 21st, 2009
0

Re: Getting Explode Array into cart

Thanks so much ardav, I'm close, I am getting info into the cart from that drop down, but it is putting the number of the array into the cart instead of the color name (red,blue,etc.)

I'ver tried this but no luck:

PHP Syntax (Toggle Plain Text)
  1. "".((isset($_POST["Color2.$value"]))?$_POST["Color2.value"]:"") ."";

I'm not sure how to get the actual color value in syntax wise. Kind of new to php.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nigelsponge is offline Offline
14 posts
since Sep 2009
Sep 22nd, 2009
-1

Re: Getting Explode Array into cart

This is because your the $_POST['color'] is picking up the array 'key' value and not the value displayed in the dropdown. Do this:

PHP Syntax (Toggle Plain Text)
  1. echo '<select name="color" id = "color">';
  2. foreach($dropdown_data as $value) {
  3. echo '<option value="'.$value.'">'.$value.'</option>';
  4. }
  5. echo '</select>';
I think that should work.
Sponsor
Featured Poster
Reputation Points: 1046
Solved Threads: 942
Sarcastic Poster
ardav is offline Offline
6,661 posts
since Oct 2006
Sep 22nd, 2009
0

Re: Getting Explode Array into cart

Click to Expand / Collapse  Quote originally posted by ardav ...
This is because your the $_POST['color'] is picking up the array 'key' value and not the value displayed in the dropdown. Do this:

PHP Syntax (Toggle Plain Text)
  1. echo '<select name="color" id = "color">';
  2. foreach($dropdown_data as $value) {
  3. echo '<option value="'.$value.'">'.$value.'</option>';
  4. }
  5. echo '</select>';
I think that should work.
Thanks so much ardav, I understand now. Appreciate your quick reply.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nigelsponge is offline Offline
14 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Error on sending mail for checked values
Next Thread in PHP Forum Timeline: pagination with mySql





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC