Skip to content
Advertisement

How to print the sql count in a view?

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 an array 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:

http://laravel.com/docs/4.2/responses

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement