Welcome Guest, Not a member yet? Register   Sign In
why wont this query return any results
#1

[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?
#2

[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.
#3

[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.
#4

[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.




Theme © iAndrew 2016 - Forum software by © MyBB