tlacaelelrl — 2012-04-13T19:09:20-04:00 — #1
Hello everyone, I am having trouble implementing COUNT in a query and would like some advice
Given a query like
SELECT * FROM #__sometable ORDER by value DESC LIMIT 0, 20
I already get the records but how can I get those 20 records plus the total amount of records in that table, what I am trying to do is provide a table which displays the records, 20 at a time and provide a list of numbers say 1, 2, 3, 4 where 1 represents records 0-20, 2 represents 21-40 and so on but want to create those numbers dynamically, so if the table contains only 20 records I want to be able no to print those numbers but if the table contains 60 records then I want to place the numbers 1, 2, 3 with a link to make the query to the respective results, in that case if I click on 3 I will dynamically create a query like
SELECT * FROM #__somtable ORDER by value DESC LIMIT 41, 20
I know I can use COUNT but don't know how to implement it in the same query so I don't have to query the database twice
r937 — 2012-04-13T19:30:47-04:00 — #2
you don't need COUNT
look up the FOUND_ROWS function in da manual
tlacaelelrl — 2012-04-13T19:54:17-04:00 — #3
Thank you for the quick answer, I read it and that does get the number of rows however I do still have to run another query right?
r937 — 2012-04-13T20:11:07-04:00 — #4
no, just your SELECT (using the SQL_CALC_FOUND_ROWS option), then retrieve the value of FOUND_ROWS
tlacaelelrl — 2012-04-13T20:14:39-04:00 — #5
Okay, I will try it, thank you for your help!