I have this
$noOfcomment = DB::select("SELECT COUNT(comment) as cs FROM comments WHERE placeid='$pid->placeid'");
But I don’t know how to print the result in a view ?
Advertisement
Answer
The
select
method will always return anarray
of results.
print_r($noOfcomment);
To print the count:
echo $noOfcomment[0]->cs;
To print the result in a view you have to pass a variable:
return View::make('viewName', array('count' => $noOfcomment[0]->cs));
Then print the result in your view:
<?php echo $count; ?>
To get more details about the database with Laravel, please check:
http://laravel.com/docs/4.2/database
To get more details about view in Laravel, please check: