[英]How do I update date without changing the older date value in php?
I'm creating a withdraw function where user can only withdraw their money in bulk.我正在创建提款 function,用户只能在其中批量提款。 If they have their transaction in the same day.
如果他们在同一天进行交易。 They can only withdraw it the day after today.
他们只能在后天收回。 Meaning that they cannot withdraw their money in the same day that they have make their transaction.
这意味着他们不能在进行交易的同一天取款。 But I got a problem when user wants to withdraw their money.
但是当用户想要取钱时我遇到了问题。 The older date_claim got changed too.
旧的 date_claim 也发生了变化。
---------------------
|id |transac_date | total | status | date_claim |
--------------------------------------------------
|abc1 | 2020-10-07 | 98 | claimed | 2020-10-10 |
|abc1 | 2020-10-22 | 124 |unclaimed | null |
|abc1 | 2020-10-24 | 145 |unclaimed | null |
in this case user are trying to claim the transaction date on 2020-10-22
在这种情况下,用户试图
transaction date on 2020-10-22
if(isset($_POST['withdraw']))
{
$id= $_GET['id'];
$sql="UPDATE tbl_kqd SET status ='claimed', date_claim = CURRENT_DATE()
WHERE id = '$id' AND
DATE(transac_date) !=CURRENT_DATE() ";
$sql_claim = mysqli_query($link, $sql);
if (mysqli_affected_rows($link) > 0){
echo "<script>alert('Successfully Claimed!')</script>";
echo "<script>window.location = 'claim.php'</script>";
}
else
echo "<script>alert('Please try tomorrow!')</script>";
}
//the output
---------------------
|id |transac_date | total | status | date_claim |
--------------------------------------------------
|abc1 | 2020-10-07 | 98 | claimed | 2020-10-24 |
|abc1 | 2020-10-22 | 124 | claimed | 2020-10-24 |
|abc1 | 2020-10-24 | 145 |unclaimed | null |
the query makes the older date changed too.该查询也使旧日期发生了变化。 I don't want it to change date that has been claimed.
我不希望它更改已声明的日期。 How do I fix this problem?
我该如何解决这个问题?
In database I declare the date_claim as date
在数据库中,我将
date_claim as date
That's happen because your Id is the same on the 3 rows.!发生这种情况是因为您的 Id 在 3 行上是相同的。! make a unique id for every row will fix it.
为每一行创建一个唯一的 id 将修复它。
---------------------
|id |transac_date | total | status | date_claim |
--------------------------------------------------
|abc1 | 2020-10-07 | 98 | claimed | 2020-10-24 |
|abc2 | 2020-10-22 | 124 | claimed | 2020-10-24 |
|abc3 | 2020-10-24 | 145 |unclaimed | null |
I understand that you want to update the first "unclaimed" row for the given id
and whose transac_date
is different than today.我知道您想更新给定
id
的第一个“无人认领”行,并且其transac_date
与今天不同。 Here is one way to phrase this:这是一种表达方式:
update tbl_kqd
set status ='claimed', date_claim = current_date()
where id = ? and transac_date <> current_date and status = 'unclaimed'
order by transac_date
limit 1
MySQL supports order by
in update
statements. MySQL 支持
order by
in update
语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.