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'); 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 |
Welcome Guest, Not a member yet? Register Sign In |