• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MySQL commend to CodeIgniter

SELECT COUNT(*) FROM job_progress WHERE status='Runing';

 This is MySQL commend please help me for CodeIgniter commend.

PHP Code:
$this->db->select('COUNT(*) AS total');

$get $this->db->get();
$result $get->result_object(); 

This should do the trick, $result contains the rows from the database

The previous answer shows how to build the statement using Query Builder (QB). QB is a great tool but a lot of the time it is not necessary. Consider what QB does - it builds query statements, which are strings used to pass commands to a database.

When the required query statement is simple and won't need to be dynamically altered then QB is serious overkill. The previous answer, while completely correct, will result in a lot of code (hundreds of lines?) being executed in order to produce the string "SELECT COUNT(*) FROM job_progress WHERE status='Runing'". It also required a lot of typing to code all those QB calls.

QB will eventually use the string it builds as an argument to the method query(). Why not remove the middle-man and go straight to that method?

PHP Code:
return $this->db
->query("SELECT COUNT(*) FROM job_progress WHERE status='Runing'")

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.