php变量增加和回声

I have a problem whit this function. i want for every 3 fetched rows to put in begining and in the end. the problem is that it works only first time only for first 3 rows...after that he output the div tag on each fetched row.

    function projects($mysqli)
    {   $ret = "";
    $count = 0;
    $divstart = "";
    $divend = "";
    $statement = $mysqli->query("SELECT id,name,description FROM projects");
    while($row = $statement->fetch_array())
    { $count++;
        if ($count == 4 ) {$divstart ='<div class="row">'; $divend = "</div>"; $count == 0;  }
        $ret = $ret. ''.$divstart.'
                        <div class="col-lg-4">
                        <div class="panel panel-primary">
                            <div class="panel-heading">
                                Primary Panel
                            </div>
                            <div class="panel-body">
                                <p>'.$row['description'].'</p>
                            </div>
                            <div class="panel-footer">
                                Panel Footer
                            </div>
                        </div>
                      </div>
                      '.$divend.' ';                                                            
    }
    return $ret;
}

What you need is a modulus operator to affect every 4th row.

 if ($count % 4 == 0) {$divstart = //....etc

You are not clearing your start/end variables, you want to clear them when $count != 4 also you had two == on your reset of $count when you only wanted one.

    if ($count == 4 ) {
      $divstart = '<div class="row">'; 
      $divend = "</div>";
      $count = 0;  
    } else {
      $divstart = '';
      $divend = '';
    }