如何发送多行值提交按钮?

时间:2012-08-11 06:55:11

标签: php mysql html

我从同一行获取值,但是fetch array的值很多。我做到了,但是有了按钮,有多少个值。如果我有5行,那么我应该有5个提交,但我想要一个提交按钮。

这是我的代码:

$result2 = mysql_query ("select * from price  where dom='$cat'",$db);
        $myrow2= mysql_fetch_array($result2);

<form action="priceupdatetes.php" method="post">
<?php


do {
    echo <<<here

   <td><input name="etiket[$myrow2[id]]" type="text" value="$myrow2[etiket]"/></td>
   <td><input name="pricestandart[$myrow2[id]]"  type="text" value="$myrow2[pricestandart]"/></td>
   <td><input name="number[$myrow2[id]]" type="text" value="$myrow2[number]"/></td>
   <td><input name="totalunper[$myrow2[id]]" type="text" value="$myrow2[totalunper]"  disabled="disabled"/></td>
   <td><input name="discount[$myrow2[id]]" type="text" value="$myrow2[discount]"/></td>
   <td><input name="totalwithper[$myrow2[id]]" type="text" value="$myrow2[totalwithper]" disabled="disabled"/></td>





  </tr>

here;


}

while($myrow2= mysql_fetch_array($result2)) ;

?>

<input NAME="id[]" TYPE=hidden value="<?php foreach($myrow2[id] as $mid) {print $mid;} ?> "/>   

<input name="submit" type="submit" value="Submit"/><br> 
</form>

HERE UPDATEPAGE.php

if (isset($_POST['etiket'])) {$etiket = $_POST['etiket']; }
if (isset($_POST['pricestandart'])) {$pricestandart = $_POST['pricestandart'];}
if (isset($_POST['number'])) {$number = $_POST['number']; }
if (isset($_POST['discount'])) {$discount = $_POST['discount']; }
if (isset($_POST['id'])) {$id = $_POST['id']; }

$totalunper=$pricestandart*$number;
$percent=$discount/100;
$totalwithper1=$totalunper*$percent;
$totalwithper=$totalunper-$totalwithper1;

foreach($id as $team_id)
{

$result = mysql_query("UPDATE price SET etiket='$etiket[$team_id]',pricestandart='$pricestandart[$team_id]',number='$number[$team_id]',totalunper='$totalunper[$team_id]',discount='$discount[$team_id]',totalwithper='$totalwithper[$team_id]' WHERE id='$team_id'");  }

如何获取具有不同id的值并更新它们?

1 个答案:

答案 0 :(得分:0)

<input NAME="id[]" TYPE=hidden value="<?php foreach($myrow2[id] as $mid) {print $mid;} ?> "/>

错了。 $ myrow2 [id]不是数组。在你的while循环中,你应该添加:

<input NAME="id[]" TYPE="hidden" value="$myrow2[id]"/>