Solved

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

Posted on 2006-06-08
11
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 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