gpt4 book ai didi

php - MYSQL-PHP 获取特定单元格(字段)的值并在 PHP IF 语句中使用它

转载 作者:可可西里 更新时间:2023-11-01 08:09:55 24 4
gpt4 key购买 nike

我希望任何人都可以帮助解决这个问题。请注意,我正在学习 PHP 和 MySQL,所以请多多包涵。我有下表:

ID  whid    securitybatch   radionumber userbatch    status       dateofentry1   AAA        123456           1        5555555    Available   11/10/2016 9:202   BBB        123456           7        1234567    Available   11/10/2016 16:503   BBB        123456           6        6666666    Deployed    11/11/2016 7:434   XXX        123456           3        2222222    Deployed    11/11/2016 19:525   XXX        123456           4        1234567    Deployed    11/11/2016 20:036   AAA        123456           6        1111116    Deployed    11/11/2016 21:437   XXX        123456           2        2222222    Deployed    11/11/2016 21:52

Im trying the get the highlighted value and use it in an IF statement, the issue is my specific requirements.

The user 1234567 has two entries on the table and eventually a lot more, i want to get the value of the status column of the latest dated entry for that user, being the one that is selected, if that makes sense...ive been trying and researching but its beating me up...

$query = "SELECT status FROM radiodata WHERE userbatch='$user' AND    MAX(dateofentry)";
$result = mysqli_query($dbc, $query);

所以我很想获得“已部署”的值,我想是一个字符串,并按如下方式使用它:

if($result === 'Deployed') {
echo 'Not returned';
} else {
echo 'Returned';
}

提前致谢,欢迎提出任何想法/解决方案。

干杯

最佳答案

当前形式的查询无效,将导致语法错误。

$query = "SELECT status FROM radiodata WHERE userbatch='$user' ORDER BY dateofentry DESC LIMIT 1";
$result = mysqli_query($dbc, $query);

你真的不应该像这样使用字符串连接,但让我们暂时把它放在一边。此查询现在将返回单行结果。

完成后,您仍然无法将其与以那种方式部署进行比较

$row = mysqli_fetch_array($result);
if ($row['status'] == 'Deployed') {

}

关于php - MYSQL-PHP 获取特定单元格(字段)的值并在 PHP IF 语句中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40559249/

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