Last active
December 17, 2015 08:49
-
-
Save Relequestual/5583353 to your computer and use it in GitHub Desktop.
Get total count for use with pagination for MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//if your query is raw sql you created, each mysql key word must be on a new line for this to work | |
$last_query = $this->db->last_query(); | |
$pattern = '/(.*)Limit (.*)/i'; | |
$new_query = preg_replace ($pattern, '', $last_query); | |
$pattern = '/(.*)Select *(.*)/i'; | |
$new_query = preg_replace ($pattern, 'SELECT \'\'', $new_query); | |
$new_query = 'Select Count(*) AS res From (' . $new_query . ') v__dynamic;'; | |
$query = $this->db->query($new_query); | |
$result = $query->row(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment