[英]$results gets multiple results back, but only last one gets updated on mysql_query. Would need all updated
[英]MySql query returns multiple results, on update everything gets updated, but I only need one of them updated
我知道,我的問題在於我的where語句中沒有唯一的標識符,僅應更新哪一行。 這就是我要說的更清楚的一點:
<?php
$res=mysql_query("select * from orders where feedback_reminder='1' ");
while($row=mysql_fetch_array($res))
{ ?>
<form method="post">
<div><input name="ship_date" type="text" id="ship_date" value="<?php echo $row['ship_date']; ?>" /></div>
<div><input name="feedback_reminder" type="text" id="feedback_reminder" value="<?php echo $row['feedback_reminder']; ?>" /></div>
<div><input type="submit" name="button" id="button" value="Update" class="submit" onMouseOver="this.className='submit submithov'" onMouseOut="this.className='submit'"/></div>
</form>
<?php
if(count($_POST)>0)
{
mysql_query("update orders set
ship_date='".$_POST["ship_date"]."',
feedback_reminder='".$_POST["feedback_reminder"]."'
where id='".$row['id']."' ");
}
}
?>
顯然,這是行不通的,因為對訂單表中的所有行,id ='“。$ row ['id']。”'為true,這就是為什么我的整個表不斷更新的原因。 我如何進行這項工作,以便僅在按下“ 更新”按鈕的位置更新該行? 我希望我已經足夠清楚了,謝謝你的幫助!
用隱藏的字段來做
$res=mysql_query("select * from orders where feedback_reminder='1' ");
while($row=mysql_fetch_array($res))
{ ?>
<form method="post">
<div><input name="ship_date" type="text" id="ship_date" value="<?php echo $row['ship_date']; ?>" /></div>
<div><input name="feedback_reminder" type="text" id="feedback_reminder" value="<?php echo $row['feedback_reminder']; ?>" /></div>
<input name="id" type="hidden" value="<?php echo $row['id']; ?>" />
<div><input type="submit" name="button" id="button" value="Update" class="submit" onMouseOver="this.className='submit submithov'" onMouseOut="this.className='submit'"/></div>
</form>
<?php
if(isset($_POST['button']))
{
mysql_query("update orders set
ship_date='".$_POST["ship_date"]."',
feedback_reminder='".$_POST["feedback_reminder"]."'
where id='".$_POST['id']."' ");
}
}
更新記錄后使用重定向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.