Im trying to use the count() function to get the count of rows with the same user_id, then display it onto a page. Is it possible to query the database using SELECT * from comments; and then use Count($user_id) in the laravel forelse loop?
What i have so far:
This function queries the database
function commentCount($id)
{
$sql = "Select count(*) FROM comment WHERE user_Id = ?";
$results = DB::select($sql, array($id));
return $results;
}
The route that calls the function:
Route::get('home', function()
{
$id = Input::get('id');
$results = getPosts();
$commentcount = commentCount($id);
return View::make('Social.home')->withPosts($results)->withCounts($commentcount);
});
code that uses the function, which is surrounded by a for else
<a href ="{{{ url("comments_post/$comment->Id") }}}"><button id="" type="button" class="btn btn-default">Comments:{{{$post->Id}}}</button></a>
Aucun commentaire:
Enregistrer un commentaire