Solved

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

Posted on 2006-06-08
11
240 Views
Last Modified: 2008-02-20
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
Comment
Question by:TheMaximumWeasel
  • 7
  • 4
11 Comments
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16865902
foreach ($_POST as $k=>$value){

// put whatever you want here


}
!
0
 
LVL 4

Author Comment

by:TheMaximumWeasel
ID: 16865919
explain that for me????

Max
0
 
LVL 4

Author Comment

by:TheMaximumWeasel
ID: 16865945
how would I use that on with what I explained above.

Max
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 16

Accepted Solution

by:
dr_dedo earned 500 total points
ID: 16865967
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
 
LVL 4

Author Comment

by:TheMaximumWeasel
ID: 16865989
ok I understand that now but one what is in the value $k

Max
0
 
LVL 4

Author Comment

by:TheMaximumWeasel
ID: 16866013
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
 
LVL 4

Author Comment

by:TheMaximumWeasel
ID: 16866017
Also the value will not go upon $i when the part of the array is submit or email.

Max
0
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16866087
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
 
LVL 4

Author Comment

by:TheMaximumWeasel
ID: 16866108
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
 
LVL 4

Author Comment

by:TheMaximumWeasel
ID: 16866464
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
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16866466
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question