• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeIngiter Query: 0 results. Pasting same query into query tool: 1 result. Uh... what?

#1
[eluser]absurdparadox[/eluser]
Strange issue going on here. I've got one query thats giving me 0 results in CodeIgniter, and 1 result in pgAdmin (postgresql).

Here's the php:
Code:
function pageinfo($page, $subpage){
        $arrReturn = array();
        $arrReturn['page']=$this->db->select('*')->from('tblcategory')->where('urlkeyword',$page)->get();
        $parentid=$arrReturn['page']->row()->id;
        $arrReturn['subpage']=$this->db->select('*')->from('tblcategory')->where('urlkeyword',$subpage)->where('parentid',$parentid)->get();
        echo $this->db->last_query();
        return $arrReturn;
    }

The first query works fine. Second query returns no results.

The query being returned from the last_query() echo:

Code:
SELECT * FROM "tblcategory" WHERE "urlkeyword" = 'test1' AND "parentid" = '0baaf830-68bb-11dd-ad8b-0800200c9a66'

Pasting this exact query into pgadmin, it gives me a result. How is this possible...? Maybe I am simply doing something wrong here?

#2
[eluser]absurdparadox[/eluser]
Also, I should mention, replacing the double ->where on the second query with only one where using an array did not fix it.

#3
[eluser]absurdparadox[/eluser]
Hmm, it seems you can't set array elements to the object in the manner I was trying. Or rather, they were setting, but the second items query was empty. I don't know if this is a restriction of the way code igniter is built or something to do with php itself (I'm very new to PHP). When I changed it to the following, it works fine.

Code:
function pageinfo($page, $subpage){
        $arrReturn = array();
        $query=$this->db->select('*')->from('tblcategory')->where('urlkeyword',$page)->get();
        $arrReturn['page']=$query->row_array();
        
        $where=array('parentid' => $arrReturn['page']['id'], 'urlkeyword' => $subpage);
        $subquery=$this->db->select('*')->from('tblcategory')->where($where)->get();
        $arrReturn['subpage']=$subquery->row_array();
        return $arrReturn;
    }

#4
[eluser]Eric Cope[/eluser]
I have issues with arrays of objects or arrays of mixed types. Glad to see you found a work around.
On a side note, isn't it fun to talk to yourself on a forum?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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