CodeIgniter Forums
Having issues with a database query in codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Having issues with a database query in codeigniter (/showthread.php?tid=52986)



Having issues with a database query in codeigniter - El Forum - 07-05-2012

[eluser]reghan[/eluser]
Hello,

I am having issues writing a db query in my model.
here is the query I am trying to write:

Code:
SELECT SystemName, process.ProcessId, RTO
FROM systems,
PROCESS , ProcessSystem, department
WHERE DepartmentId = Department
AND process.ProcessId = ProcessSystem.ProcessId
AND ProcessSystem.SystemID = systems.SystemID
AND DepartmentId =8
AND process.ProcessId = 2;

I tested the above SQl statement and it worked. I would like to have DepartmentId = 8
and ProcessId = 2 passed in as variables, so here is what I wrote in the model.

Code:
function getSysPro($dep, $pro)
{
  $department = 'department';
  $pro_processId = "ProcessSystem.ProcessId";
  $ps_SystemID = "systems.SystemID";
  
  $this->db->select('SystemName','RTO');
  $this->db->from('department');
  $this->db->from('systems');
  $this->db->from('process');
  $this->db->from('ProcessSystem');
  $this->db->where('DepartmentId', $department);
  $this->db->where('process.ProcessId', $pro_processId);
  $this->db->where('ProcessSystem.SystemID', $ps_SystemID);
  $this->db->where('DepartmentId', $dep);
  $this->db->where('process.ProcessId', $pro);
  
  return $this->db->get();


}

I am not getting any values returned, so I am not sure what the problem is.

if anyone could provide assistance that would be great!

Thanks!!


Having issues with a database query in codeigniter - El Forum - 07-05-2012

[eluser]Aken[/eluser]
Use $this->db->last_query() to see what is actually being queried, and see where the problem is.