MySQL commend to CodeIgniter - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: MySQL commend to CodeIgniter (/showthread.php?tid=70790) |
MySQL commend to CodeIgniter - azmath - 05-30-2018 SELECT COUNT(*) FROM job_progress WHERE status='Runing'; This is MySQL commend please help me for CodeIgniter commend. RE: MySQL commend to CodeIgniter - Krycek - 05-30-2018 PHP Code: $this->db->select('COUNT(*) AS total'); This should do the trick, $result contains the rows from the database RE: MySQL commend to CodeIgniter - dave friend - 05-30-2018 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 |