gpt4 book ai didi

php - IF 语句未按预期运行

转载 作者:行者123 更新时间:2023-11-29 03:08:11 24 4
gpt4 key购买 nike

如果用户已登录,我想显示用户的全名。如果没有,则应显示文本“登录”。

这是我目前所拥有的:

session_start();

$session = $_SESSION['username'];

include "config.php";

$sql = mysql_query("SELECT * from user");
while($d=mysql_fetch_array($sql))
{
if($d['status']=='online' and $_SESSION['username'] == $d['username'])
{
$full_names = $d['full_name'];

echo $full_names;
}
else
{
echo "Login";
}
}

有什么想法吗?

最佳答案

您应该使用 SQL WHERE(如@ThiefMaster 所述),但只是为了回答您的问题:

$full_names = false;
while($d=mysql_fetch_array($sql)) {
if($d['status']=='online' and $_SESSION['username'] == $d['username']) {
$full_names = $d['full_name'];

echo $full_names;
}
}

if(!$full_names) {
echo "Login";
}

关于php - IF 语句未按预期运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12292099/

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