• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

$_POST to array URGENT 500 POINTS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I have a form that php makes and it displays a certain # of drop downs depending on a varaible. Now on the page that recieves then info how can I use some kind of loop to retrieve the info until there isn't any left. So it will check to see if $_POST['tag1'] is set and if it is get some data from mysql then echo then go back to the beginning of the loop and check for $_POST['tag2'] until if gets to one that isn't set then ends the loop.

Max
0
TheMaximumWeasel
Asked:
TheMaximumWeasel
  • 7
  • 4
1 Solution
 
dr_dedoCommented:
foreach ($_POST as $k=>$value){

// put whatever you want here


}
!
0
 
TheMaximumWeaselAuthor Commented:
explain that for me????

Max
0
 
TheMaximumWeaselAuthor Commented:
how would I use that on with what I explained above.

Max
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
dr_dedoCommented:
in the form action page (that handles the form )

foreach ($_POST as $k=>$value){ // this is a loop through all variables in the POST array

$sql = "select * from table1 where name=$value"; // every element in the post array can be used as $value variable. Do what you want to it


} // the loop will continue as long as POST array still has results
your form may contain some other stuff that are added to post array and you don't want to include in your loop (e.g. a submit button), you can put these variables in array and ignore them
e.g.

$items_to_ignore =array ('submit','email');
foreach ($_POST as $k=>$value){
if (!in_array($k,$items_to_ignore)){
      $sql = "select * from table1 where name=$value";
      // put rest of code here
   }
}
0
 
TheMaximumWeaselAuthor Commented:
ok I understand that now but one what is in the value $k

Max
0
 
TheMaximumWeaselAuthor Commented:
Also is that act as a loop so if I put $i++ at the end of it, the value will go up each time.

Max
0
 
TheMaximumWeaselAuthor Commented:
Also the value will not go upon $i when the part of the array is submit or email.

Max
0
 
dr_dedoCommented:
foreach ($_POST as $k=>$value){

// $k is the key of the array (i.e. form element name say email, fname, password
// $value is the value of this form element say fnam= xxxx, password=xxxx, email = xxx@xxx.xxx

}
you don't increment anything here, the loop will do it all
0
 
TheMaximumWeaselAuthor Commented:
well I need to increment it cause of how I am using it. Each $_POST variable contains a number that is the ID of the tag. So then everytime it loops it appends a string and ads the varialbe heres what I am talking about.

everytime it repeats it ads  "&tag" . $i . "=$value"; to the string and $i is teh variable that increments cause the form is tags 1 through a certain #.

Max
0
 
TheMaximumWeaselAuthor Commented:
nevermind I got it to increment correctly by putting it inside the if so it wouldn't increase on something besides the data I want.

Max
0
 
dr_dedoCommented:
mmm
you can use this
$items_to_ignore =array ('submit','email');
foreach ($_POST as $k=>$value){
if (!in_array($k,$items_to_ignore)){
      echo $value."&tag" . $i . "=$value";
      // put rest of code here
   }
}

or if your form elements are numbered, e.g. arg1, arg2
$c = count($_POST) + 1;
for ($i=1; $i<$c;$i++) {
$key = 'arg'.$i;
if (isset ($_POST[$key])) {

      now you have POST['arg1'], then arg2, etc....

}


}
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now