CodeIgniter Forums
why wont this query return any results - 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: why wont this query return any results (/showthread.php?tid=43091)



why wont this query return any results - El Forum - 06-29-2011

[eluser]Uplift[/eluser]
Any idea why this query wont return any results.. probably something stupid but i can't see it.

Code:
function getUpcoming() {
        
        $this->db->order_by("datet", "desc");
        $this->db->select('title, datet');
        $todaysDate = date('Y-m-d');
        $queryUp = $this->db->get_where('events', array('datet' => '<= $todaysDate'));
        
        return $queryUp->result_array();
    
    }

this should select the title and datet from the events table if datet is less than or equal to $todaysDate

basically, it should show all events that haven't happened yet. I also want to limit it to 10 results ordered by date (closest event first)

I have used $queryUp because i already have a query above using $query to return other results, do i need to do that?


why wont this query return any results - El Forum - 06-29-2011

[eluser]cideveloper[/eluser]
set

Code:
$this->output->enable_profiler(TRUE);

and see what query is being generated. Then try that query directly in you database and see if you get a result.


why wont this query return any results - El Forum - 06-29-2011

[eluser]Seb[/eluser]
You should try this:

Code:
$queryUp = $this->db->get_where('events', array('datet <=' => $todaysDate));

And by the way, the variable needs to have another name only if you care about the previous result set.


why wont this query return any results - El Forum - 06-29-2011

[eluser]adityamenon[/eluser]
You could also try
Code:
$this->db->last_query(); exit();
just after your query line, to see what query was generated (code execution stops and you'll see the result in the browser). And yes, Seb is right. <= operator should be on the left side, right after the column. Plus, $todaysDate was put inside single quotes so PHP was not parsing the variable. Either remove the quotes or add in double quotes.