Jump to content

<select>


Kano

Recommended Posts

Hi there,

 

I have a query regarding <select> name:

 

The script runs through a for loop for each select which gets the qty's from the DB, so the user can only select the maximum thats available in stock. Each select is given a name, which is the record ID from the DB ($wsi_id_arr[$num]). So the first select will be <select name="VB001"> for example.

 

However, the problem i am having is how do I get at this in another script, for example, so far I have:

 

for($ordercnt=0;$ordercnt<$num;$ordercnt++)

{

if(...................

 

thanks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/41444--/
Share on other sites

Use a foreach loop to loop through as associative array. You can use $var => $value to look through all the keys.

 

foreach ($_POST as $var => $value) {
# loop through post vars and add up anthing that has "VB" in the variable name.
  if (strstr ($var, "VB")) {
    $total += $value;
  } 
}

if ($total > 0) {
# user has made a purchase
}

/*
Note if you did $$var = $value you would get the variable $VB0001 etc.
*/

 

But then, why would a Select form field be submitting many VBXXXX values surely it would only be 1?

If so you would access that with the name attribute of your select field e.g

 

<select name='something'>

$something = $_POST['something'];

 

Does that help?

Link to comment
https://forums.phpfreaks.com/topic/41444--/#findComment-200827
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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