解析错误:语法错误,意外的“else”(T_ELSE)[关闭]

2023-12-22

我编辑此代码以在 select 为空时显示消息,并收到此错误:

 Parse error: syntax error, unexpected 'else' (T_ELSE) in /nginx/user/reports.php on line 235

这是代码:

 $stmt = $mysqli->prepare("SELECT date, impressions, balance, username FROM reports WHERE username = '$username' and date between '$firstDay' AND '$lastDay'");
    $stmt->execute();
    $stmt->store_result();
    $rows = $stmt->num_rows;
    mysqli_stmt_bind_result($stmt,$date,$impressions,$balance,$username);
       if ($rows > 0){
       while (mysqli_stmt_fetch($stmt)) {   
           $ecpm_t3 = $balance*1000;
       $ecpm3 = $ecpm_t3/$impressions;
    $rate = number_format((float)$ecpm3, 2, '.', '');
     echo"<tr>
            <td class=\"nn\" style=\"text-align:center;\" align=center>$date</td>
            <td class=\"nn\" style=\"text-align:center;\" align=center>$impressions</td>
            <td class=\"nn\" style=\"text-align:center;\" align=center>$$rate</td>
            <td class=\"nn\" style=\"text-align:center;\" align=center nowrap>$$balance</td>
        </tr>";
       } else {
        echo"<tr>
            <td colspan=\"4\" class=\"nn\" style=\"text-align:center;\" align=center>Not rows</td>
        </tr>";
    }
        }

第 235 行是:

   } else {

我该如何解决这个错误?有什么不好?


工作示例(固定和格式化):

$stmt = $mysqli->prepare("SELECT date, impressions, balance, username FROM reports WHERE username = '$username' and date between '$firstDay' AND '$lastDay'");
$stmt->execute();
$stmt->store_result();
$rows = $stmt->num_rows;
mysqli_stmt_bind_result($stmt, $date, $impressions, $balance, $username);
if ($rows > 0)
  {
    while (mysqli_stmt_fetch($stmt))
      {
        $ecpm_t3 = $balance * 1000;
        $ecpm3   = $ecpm_t3 / $impressions;
        $rate    = number_format((float)$ecpm3, 2, '.', '');
        echo "<tr>
                <td class=\"nn\" style=\"text-align:center;\" align=center>$date</td>
                <td class=\"nn\" style=\"text-align:center;\" align=center>$impressions</td>
                <td class=\"nn\" style=\"text-align:center;\" align=center>$$rate</td>
                <td class=\"nn\" style=\"text-align:center;\" align=center nowrap>$$balance</td>
              </tr>";
      }
   }
   else
     {
       echo "<tr>
               <td colspan=\"4\" class=\"nn\" style=\"text-align:center;\" align=center>Not rows</td>
             </tr>";
     }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

解析错误:语法错误,意外的“else”(T_ELSE)[关闭] 的相关文章

随机推荐