Getting Explode Array into cart

Thread Solved

Join Date: Sep 2009
Posts: 6
Reputation: nigelsponge is an unknown quantity at this point 
Solved Threads: 0
nigelsponge nigelsponge is offline Offline
Newbie Poster

Getting Explode Array into cart

 
0
  #1
Sep 21st, 2009
Hi , I am using an explode function to split some comma separated colors into a drop down list.

  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,004
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 130
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

Re: Getting Explode Array into cart

 
-1
  #2
Sep 21st, 2009
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.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 6
Reputation: nigelsponge is an unknown quantity at this point 
Solved Threads: 0
nigelsponge nigelsponge is offline Offline
Newbie Poster

Re: Getting Explode Array into cart

 
0
  #3
Sep 21st, 2009
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,004
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 130
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

Re: Getting Explode Array into cart

 
-1
  #4
Sep 22nd, 2009
This is because your the $_POST['color'] is picking up the array 'key' value and not the value displayed in the dropdown. Do this:

  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.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 6
Reputation: nigelsponge is an unknown quantity at this point 
Solved Threads: 0
nigelsponge nigelsponge is offline Offline
Newbie Poster

Re: Getting Explode Array into cart

 
0
  #5
Sep 22nd, 2009
Originally Posted by ardav View Post
This is because your the $_POST['color'] is picking up the array 'key' value and not the value displayed in the dropdown. Do this:

  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.
Reply With Quote Quick reply to this message  
Reply

Tags
dropdownlist, explodefunction, php

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC