开发者

PHP foreach with jquery dynamic cloned fields

开发者 https://www.devze.com 2023-02-25 16:32 出处:网络
I have a script where jquery clones a fieldset box with an building, a floor, and a wing (input fields) The user can create as many of these fieldsets as they need.What I am trying to figure out is th

I have a script where jquery clones a fieldset box with an building, a floor, and a wing (input fields) The user can create as many of these fieldsets as they need. What I am trying to figure out is this.

I need to main the areas together otherwise I co开发者_JAVA技巧uld just loop throug the aray like this.

   foreach ($_POST[$key] as $itemvalue)       { 
         $message .= "\n".$key. " : ".$itemvalue; 
      }

My first thought was to do this, but of course this was dumb of me

foreach ($_POST['building'] as $value) {
    $count++;
    $message .="\n Area" . $count;
    $message .= "\n Building: ". $value;
    foreach ($_POST['floor'] as $value2){
    $message .= "\n Floor: ". $value2;
        }
    foreach ($_POST['wing'] as $value3){
    $message .= "\n Wing: ". $value3;
        }
    }

as it just ends up putting each of the floors and wings under every building instead of keep them separate.

my next thought was to put them into one long for each separated by and && symbol, but apparently foreach doesn't work this way.

Does anyone have any suggestions on how I can do this?

@stewie I made the modifications you suggested, but I am pretty sure this won't work.

foreach ($_POST['floor'] as $value)
    { $floor = $value; }
foreach ($_POST['wing'] as $value2) { $wing = $value2; }
foreach ($_POST['building'] as $value3)
    { $building = $value3; $building .= $floor; $building .= $wing; }

This is my entire code, the output I am trying to get is this

Area #1 Building : Building 1 Floor : 2 Wing : East

Area #2 Building : Building 2 Floor : 5 Wing : North

<?php 
if(isset($_POST['submit'])) {

$mailto = "me@myemail.com"; 
$subject = "form"; 
$message = "Values submitted from web site form:"; 
$header = "From: Jeremiah <Jeremiah@myemail.com>"; 

foreach ($_POST['floor'] as $value)

{

$floor = "\nFloor : " . $value;
}

 foreach ($_POST['wing'] as $value2)
 {
$wing = "\nWing : ".$value2;
 }

 foreach ($_POST['building'] as $value3)
 {
$building = "\n\nBuilding " . $value3;
$building .= $floor ;
$building .= $wing;
$message .= $building;
}




 mail($mailto, $subject, $message, $header); 
 }

?>


dirty, but keeping up with your original design !

  foreach ($_POST['building'] as $value) {
        $count++;
        $message ="\n Area" . $count;
        $message .= "\n Building: ". $value;
        $message2='';
        foreach ($_POST['floor'] as $value2){
        $message2 .= "\n Floor: ". $value2;
            }
        foreach ($_POST['wing'] as $value3){
        $message2 .= "\n Wing: ". $value3;
          }
    echo $message;
    echo $message2;
            }

        }

What you should do is this:

foreach(floor){set  $floor} 
foreach(wing) {set $wing}

Main foreach

foreach(building)
{
   $building = ...
   $building .= $floor
   $building .= $wing
}
0

精彩评论

暂无评论...
验证码 换一张
取 消