我正在为MySQL编写代码以获取第一行,其状态为"无效"并使它们活跃",但每当我尝试更新列并使其“活跃”时#34;我的查询更新了多行而不是单行。
date_default_timezone_set('Asia/Kolkata');
$d = time ();
$date = date("Y-m-d", $d);
$customer_id="1470831854";
$member_details="SELECT * FROM login_update WHERE customer_id ='$customer_id' AND status='inactive' ORDER BY id ASC LIMIT 1 ";
$member = mysql_query($member_details);
while($list = mysql_fetch_array($member)){
$status = $list['status'];
$id = (int)$list['id'];
}
$date_update = "UPDATE login_update SET status='active' WHERE id = '$id'";
$enter_date = mysql_query($date_update);
答案 0 :(得分:0)
我认为您的代码应该按照以下方式进行更改
while($list = mysql_fetch_array($member)){
$status = $list['status'];
$customerId = (int)$list['customer_id'];
}
$date_update = "UPDATE login_update SET status='active' WHERE id = '$customerId'";
$enter_date = mysql_query($date_update);
因为如果你得到$ list ['id'],它总是只返回数据库中的1个唯一值,然后只更新一个记录。 我认为ID是您的主键。