Welcome Guest, Not a member yet? Register   Sign In
MySQL commend to CodeIgniter
#1

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

 This is MySQL commend please help me for CodeIgniter commend.
Reply
#2

PHP Code:
$this->db->select('COUNT(*) AS total');
$this->db->from('job_progress');
$this->db->where('status''running');

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

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

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'")
 
            ->result(); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB