gpt4 book ai didi

php - 如何使用 PHP 更新 MySQL 中的不同值

转载 作者:行者123 更新时间:2023-11-29 18:41:55 25 4
gpt4 key购买 nike

我有一个问题不知道如何解决。

我想为 MySQL 中的所有“ID”更新不同的值。

我使用 PHP 来实现此目的,这是我的代码:

//First ID check 

$result = mysqli_query($conn,"SELECT subscription_end, today_date FROM users_manager WHERE id=62");

while($date = mysqli_fetch_array($result))
{
$date['subscription_end'];
$date['today_date'];

if ($date['subscription_end'] <= $date['today_date']) {
$update = "UPDATE users_manager SET status='of' WHERE id=62";
} else {
$update = "UPDATE users_manager SET status='on' WHERE id=62";
}
}

//Second ID check
$result = mysqli_query($conn,"SELECT subscription_end, today_date FROM users_manager WHERE id=50");

while($date = mysqli_fetch_array($result))
{
$date['subscription_end'];
$date['today_date'];

if ($date['subscription_end'] <= $date['today_date']) {
$update = "UPDATE users_manager SET status='off' WHERE id=50";
} else {
$update = "UPDATE users_manager SET status='on' WHERE id=50";
}
}

当我添加新用户并且该用户具有新 ID 示例 55 时,我必须再次添加一行代码来检查新用户。

你能告诉我如何随时查看所有这些以及新老用户吗?

最佳答案

试试这个,一切都记录在案..如果您没有得到任何信息,请问我。

/**
* UserId: This variable holds the userId,
* You have to bring it from database and referenced to this variable.
*/
$userId = 10;
// This variable represents the status column in the 'user_manager' Table.
$status = null;

$result = mysqli_query($conn,"SELECT subscription_end, today_date FROM
users_manager WHERE id={$userId}");

while($date = mysqli_fetch_array($result))
{
$date['subscription_end'];
$date['today_date'];

$status = ($date['subscription_end'] <= $date['today_date']) ? 'off' : 'on';

$update = "UPDATE users_manager SET status={$status} WHERE id={$userId}";

}

关于php - 如何使用 PHP 更新 MySQL 中的不同值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44894492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com