-3

I edit this code to display a mesaje when select is null and i get this error:

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

This is code:

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

And line 235 is:

   } else {

How i can resolve this error ? What is bad ?

5
  • You forgot to close your if statement. Commented Jan 12, 2014 at 13:42
  • 2
    while can't have an else branch. Count curly braces, indent properly, use IDE. Commented Jan 12, 2014 at 13:42
  • Your fixed example is here: ideone.com/wjbqCa Commented Jan 12, 2014 at 13:45
  • @ Ilia Rostovtsev i put your code and not show messaje Commented Jan 12, 2014 at 13:49
  • @user3164987, well see the answer then.. Commented Jan 12, 2014 at 13:53

2 Answers 2

1

Working example (fixed and formatted):

$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>";
     }
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

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


?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.