Kar*_* RK 0 php mysql if-statement while-loop
这是我的编码
<?php
try
{
$stmt = $conn->prepare("SELECT * FROM registration");
$stmt->errorInfo();
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
echo "<tr>";
echo "<td>". $row['Autoid'] ."</td>";
echo "<td>". $row['Name'] ."</td>";
if($_SESSION['sesuname'])
{
echo "<td>Its You ". $_SESSION['sesuname'] ."</td>";
}
else if(!$_SESSION['sesuname'])
{
echo '<td>Follow</td>';
}
echo "</tr>";
}
} catch (PDOException $e) {
'Database Error : ' .$e->getMessage();
}
?>
Run Code Online (Sandbox Code Playgroud)
我正在尝试显示Follow选项并在最终中登录用户名td.但是,此编码始终显示所有行中的登录用户名.我不知道我哪弄错了?
我想你的病情应该是,
if($_SESSION['sesuname'] == $row['Name'])
{
echo "<td>Its You ". $_SESSION['sesuname'] ."</td>";
}
else
{
echo '<td>Follow</td>';
}
Run Code Online (Sandbox Code Playgroud)