No "returns". COUNT()
results in the total amount of items he has found that satisfy the established query. How much information results? One. Just the total amount, a single amount. When you say despise a value, you are already despising everything that has worked, so it makes sense to have this behavior. It makes no sense to use OFFSET
with COUNT()
.
If you want to know how many lines a query resulted can do this:
SELECT COUNT(*) AS total FROM (SELECT 1 FROM noticias ORDER BY data_noticia DESC LIMIT 30 OFFSET 2) AS resultado;
I put in the Github for future reference.
You make your query and the result of it you make the account. Remembering that it will give a value up to 30. If you have more than 30 will always be 30.
I can’t guarantee it’s the best way, but the basis is this.
If you are actually taking the data of the first query then you can count how many lines were delivered by the database for your direct application in the application. You can take the size of array obtained or can use the function mysqli_num_rows()
.
then just make two querys, one to count and the other to return the data.
– Guilherme Nascimento
Take this * out of the query, put only the columns you will actually use, if you want to optimize.
– Bacco
First of all, do you want to know the total of the results, or the total only after applying the offset? For each case the solution is different.
– Bacco