$query->num_rows(); // Value is not expected .. This is not the total value |
[eluser]soprabaixar1[/eluser]
How do I know the total number of rows from a query in which the query was performed as follows: Code: $query = $this->db->orderby(....); If I do, it works, but I think there is a better way, even on account of the performance. The way I'm using is creating a new variable ... Code: $query2 = $this->db->like('msg', 't');
[eluser]WanWizard[/eluser]
num_rows() returns the number of rows in the resultset, not in the table. If you want that, use Code: $this->db->count_all('table'); Read the manual, it's excellent. This is documented.
[eluser]soprabaixar1[/eluser]
You do not understand my question. I have a query to the database, and I need the number of rows this query, but when using the parameter that references to "limit", example: Code: $query = $this->db->orderby (..., ...); I can not get the total rows using: Code: $ query-> NUM_ROWS () / / will return 20 rows, because of the limit My temporary solution was to create a new query to the database only to calculate the number of lines: Code: $query2 = $this->CI->db->like("user", ...); The problem that the database has many records and many users access, it affects system performance. I wonder if another way to solve this.
[eluser]wh1tel1te[/eluser]
You cannot do this in one query. You will have to do two queries: one without the limit to get the total rows, and one with the limit to limit your returned data. EDIT: If doing two queries is affecting system performance, you might want to cache the total rows value. See Query Caching in the user guide.
[eluser]InsiteFX[/eluser]
Code: function get_total_rows($table = '') InsiteFX
[eluser]soprabaixar1[/eluser]
Cache is good when it happens many actions in the database (insert, delete, update), and is not the case. I decided a little better than the previous form, this time I do not need to create a variable "$query2" going all the information again, just enjoy the variable $query and a line do I make the call with the values refernte to "limit" of course it still does not consider ideal. The two temporary solution was as follows: Code: ...
[eluser]meemeo[/eluser]
u can use Code: $query = $this->db->orderby(....); hope is ur Ans ^ ^
[eluser]gRoberts[/eluser]
You have to use a combination of SQL_CALC_FOUND_ROWS and FOUND_ROWS(), which results in two queries. Take a look at http://stackoverflow.com/questions/74218...mit-clause |
Welcome Guest, Not a member yet? Register Sign In |