• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having issues with a database query in codeigniter

#1
[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!!

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.