简体   繁体   中英

Codeigniter run mysql query and echo number of returned rows

<?=$this->db->count_all_results('users')?>

Hi, I am stuck on something. How can run a query like the below count and echo all of the returned rows? I am currently using the above statement but I need this improvement.

<?php $aa = $this->db->query("SELECT * FROM users WHERE itemNumber = 1");

Use num_rows() method

<?php
 $aa = $this->db->query("SELECT * FROM users WHERE itemNumber = 1");
echo $aa->num_rows();

?>
$this->db->query("SELECT u.*, COUNT(u_all.*) FROM users u, users u_all WHERE u.itemNumber = 1");
$numRows = $this->db->query("SELECT count(*) FROM users WHERE itemNumber = 1");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM