$ _POST数组的顺序错误?

时间:2016-07-21 15:06:01

标签: html arrays post submit

喜欢通过$ _POST提交数组,它只适用于一个foreach,如何组合两个foreach-arrays而不会使所有内容都加倍?

我用" keTitle"和" keSoll",但一次只能工作一次......

HTML:

<div class="table-responsive">
<table class="table table-striped">
    <thead>
        <td>Kühlgerät</td>
        <td>Soll</td>
        <td>Ist</td>                
    </thead>
    <tbody> 

<?php

$todo_query = mysqli_query($db, "SELECT * FROM temp_ke WHERE ListID = '1'");

while($row2 = mysqli_fetch_object($todo_query))
{
?>  
        <tr>
            <th scope="row">
                <?php echo "$row2->keTitle"; ?>
                <input name="Title[<? echo "$row2->keTitle";?>]" value="<? echo "$row2->keTitle";?>" type="hidden">
            </th>                               
            <td><?php echo "$row2->keSoll"; ?> °C<br>
                <input name="SollWert[<? echo "$row2->keSoll";?>]" value="<? echo "$row2->keSoll";?>" type="hidden">
            </td>
            <td>
                <input class="shortinput" name="IstWert[]" value="" type="text"> °C<br>
            </td>                                       
        </tr>
<?php }} ?>         
    </tbody>
</table>

<div class="tablefooter">Ausgefüllt von: <input name="Mitarbeiter" value="" type="text"></div>
<br>
<input type="submit" class="btn btn-default" value="Temperaturen eintragen">

</form>     
</div>

下一页到$ _POST到:

<?php

    foreach ($_POST['Title'] as $keTitle) {
        foreach ($_POST['SollWert'] as $keSoll) {
            echo "$keSoll<br>";
            echo "$keTitle<br><br>";    
        }
    }


?>

1 个答案:

答案 0 :(得分:0)

表格价值

$_POST['Title'] = 'Mein Titel';
$_POST['SollWert'] = '123';

那就是数组:

$ksTitle = $_POST['Title'];
$keSoll = $_POST['SollWert'];

echo "$keSoll<br/>";
echo "$keTitle<br/>";

或在foreach中:

foreach( $_POST AS $value){
  echo $value . "<br/>";
}

输出:

  

Mein Titel

     

123