-1

我从同一行获取值,但有很多值fetch array。我做到了,但是使用按钮,有多少个值。如果我有 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>

这里是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' 的值并更新它们?

4

1 回答 1

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]"/>
于 2012-08-11T07:06:14.010 回答