MySQL's keywords:
Sql_calc_found_rows
After viewing the manual, it is found that this keyword is useful when querying the total number of results (not limited by Limit) that meet the filter criteria.
For example:
Copy Code code as follows:
SELECT sql_calc_found_rows tid from cdb_threads WHERE fid=14 LIMIT 1, 10;
Let's say there are 1000 conditions, and here we return 10.
Use now
Copy Code code as follows:
SELECT found_rows () as rowcount;
The returned rowcount is 1000;
This saves a significant amount of time by saving duplicate queries for select COUNT (*) as ROWCOUNT.
Here's how to put it in the swim flavor:
Copy Code code as follows:
function Mail_list_sent ($uid, $start) {
Note that there is no comma between the sql_calc_found_rows uid
$query = "Select Sql_calc_found_rows uid, Real_name, current_city, Msg_uid, Sender_flag,".
"Msg_title, msg_content from". Tt_dbtablepre. "Mailbox as MB1,". Tt_dbtablepre.
"User as USR1 WHERE mb1.sender_id=usr1.uid and mb1.sender_id= $uid and sender_flag > 0 LIMIT $start,". Tt_pagesize;
$mails = $this->db->fetch_all ($query);
Query the number of rows in the select that meet the criteria, regardless of the limit clause
$max _count = $this->db->fetch_first ("Select Found_rows () as rowcount");
$tmp [' state_code '] = 200;
$tmp [' info '] = "OK";
$tmp [' list '] = $mails;
$data = Json_encode ($tmp);
return $data;
}