3
<?=$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");
0

3 Answers 3

8

Use num_rows() method

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

?>
Sign up to request clarification or add additional context in comments.

1 Comment

thanks man. I couldn't seem to figure out how to do it on an active record object. i new how to do it in native php though lol
0
$this->db->query("SELECT u.*, COUNT(u_all.*) FROM users u, users u_all WHERE u.itemNumber = 1");

Comments

0
$numRows = $this->db->query("SELECT count(*) FROM users WHERE itemNumber = 1");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.