解析错误:语法错误,意外'其他'(T_ELSE)

时间:2014-01-12 13:41:01

标签: php

我编辑此代码以在select为null时显示mesaje并且我收到此错误:

 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 {

我如何解决此错误?什么是坏事?

2 个答案:

答案 0 :(得分:2)

工作示例(已修复并已格式化):

$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>";
     }

答案 1 :(得分:1)

试试这个

<?php

$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>";
    }


?>