?
Solved

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

Posted on 2006-06-08
11
Medium Priority
?
269 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
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 16

Accepted Solution

by:
dr_dedo earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.
Suggested Courses

770 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