CodeIgniter Forums
Query Builder "FROM * table AS a" - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Query Builder "FROM * table AS a" (/thread-67638.html)



Query Builder "FROM * table AS a" - meSmashsta - 03-18-2017

How do you do that in code igniter? I have this Stored Procedure that I want to reproduce in Codeigniter's Query Builder. Thanks in advance guys!

Code:
DELIMITER //

CREATE PROCEDURE get_reports(
IN record_start INT,
IN records_to_retrieve INT
)
BEGIN
   
   DECLARE r_start INT DEFAULT 0;
   DECLARE r_retrieve INT DEFAULT 0;
   SET r_start = record_start - 1;
   SET r_retrieve = record_start * records_to_retrieve;
   
   SELECT a.id,
           b.id AS employee_id,
           CONCAT(b.last_name, ", ", b.first_name, " ", b.middle_name) AS full_name,
           c.id AS machine_id,
           c.title AS machine,
           d.title AS hstatus,
           a.created_on,
           a.action_on,
           a.edit_on,
           a.problems_encountered,
           a.corrective_action,
           a.root_caused,
           a.remarks,
           a.item_replaced
   FROM reports AS a
   INNER JOIN employees AS b ON b.id = a.employee_id
   INNER JOIN machines AS c ON c.id = a.machine_id
   INNER JOIN hstatus AS d ON d.id = a.hstatus_id
   LIMIT r_start , r_retrieve;

END //

DELIMITER ;

This does not work, Stackoverflow said that the LIMIT clause doesn't take parameters only on new versions... How do I see my MySql version in my phpadmin?


RE: Query Builder "FROM * table AS a" - meSmashsta - 03-18-2017

I got it working.