Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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