-2
I need to show the number of records belonging to a registered mobile number.
in the log table have the columns NUMBER and MESSAGES need to show the user the amount of messages that the registered numbers have.
By a @foreach I show on the screen all the records of the LOGS table that are: NUMBER, REGISTRATION DATE AND MESSAGES
but the COLUMN MESSAGES I need to be summed all the lines that belong to the NUMBER X and printed on the screen the total.
I registered to test each number 2 times, so should show on the screen that all numbers have 2 messages.
but is returning me the number 7 which is the amount of records in TABLE LOGS.
I tried in many ways, but without success.
I currently have the code
$numero = '{{ $logs->numero }}';
$teste = DB::table("logs")->select("mensagens")->where('numero', '<=',
$numero)->count();
Apply a grouping to the column
numero
, otherwise thecount
will return the quantity of the entire table.– Woss
$test = DB::table('logs') ->select('messages', DB::raw('Count(*) the numbers') ->groupBy('messages') ->get(); I tried that, but it didn’t work. Can you give me an example of your answer ? @Woss
– André Luiz Mardonis
I recommend reviewing the SQL materials you studied. You need to group by number, not by messages.
– Woss
is sorry ignorance. I am beginner in Laravel. and I’m half lost.
– André Luiz Mardonis
You could do this directly in Mysql?
– Woss
I had to go to the database.php file and make 'Strict' => false. with this I got a better result.
– André Luiz Mardonis