這是我的代碼,我無法運行我的簡單條件。我已經使用了所有的方法,但它不起作用。正如我想如果計數可用,然後顯示計數,如果沒有,然後回聲0。我知道這很簡單,但我堅持它。if else condition is notly properlly
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$db = "usman";
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
$result = $dbh->query(
"SELECT COUNT(*) as cnt
FROM ams
where empid= {$_SESSION['sess_user_id']}
GROUP BY leavetype
HAVING leavetype = 'Annual'"
);
if (!$result) {
echo "<td>";
echo 0;
echo "</td>";
} else {
foreach ($result as $row) {
echo "<td>" . $row['cnt'] . "</td>";
echo "<br>";
}
}
?>
where'session_start()'? – devpro
你錯過了其他的'}'。你只有for循環的'}' –