Welcome Guest, Not a member yet? Register   Sign In
[solved] using active records WHERE with now()
#1

[eluser]Pale Rider[/eluser]
Ok, I'm a bit stumped. This returns no rows:

Code:
function get_funerals()
    {
        $this->db->where('visitation >', 'NOW()');
        $query = $this->db->get('funerals');
        return $query->result();
    }

but if I open up phpMyAdmin and do:

Code:
SELECT *
FROM `funerals`
WHERE visitation > NOW( )

.. that returns the right results.

Is AR doing some sort of escaping that's messing up that query. Not sure why that is not working :o

cheers
#2

[eluser]bretticus[/eluser]
try printing the compiled query out to your browser:

Code:
function get_funerals()
    {
        $this->db->where('visitation >', 'NOW()');
        $query = $this->db->get('funerals');
        echo $this->db->last_query();
        return $query->result();
    }

or turn on profiling to get a look:

Code:
function get_funerals()
    {
        $this->output->enable_profiler(TRUE);
        $this->db->where('visitation >', 'NOW()');
        $query = $this->db->get('funerals');
        return $query->result();
    }

Oh by the way, when you return $query->result() you are just returning one row.
#3

[eluser]Pale Rider[/eluser]
hmmm well i did

Code:
function get_funerals()
    {
        $this->db->where('visitation >', 'NOW()');
        $query = $this->db->get('funerals');
        echo $this->db->last_query();
        return $query->result();
    }

and it gave me

Code:
SELECT * FROM (`funerals`) WHERE `visitation` > 'NOW()'

o_O


result just returns one result? What should I be using? I have many queries such as

Code:
function get_orders_stage1()
    {
        $this->db->select('ID, order_number, time_sales, order_stage, customer_name, timeframe, time_sensitive');
        $query = $this->db->get_where('orders', array('order_stage' => '1') );
        return $query->result();
    }

.. and they seem to be returning all the right rows.
#4

[eluser]bretticus[/eluser]
try
Code:
$this->db->where('visitation >', 'NOW()', TRUE);

EDIT:

Sorry, that would be FALSE instead of TRUE.

If that doesn't work try:

$this->db->where('visitation > NOW()');
#5

[eluser]Pale Rider[/eluser]
Hmm, just tried

Code:
$this->db->where('visitation >', 'NOW()', TRUE);

but no nice.

I guess I can try doing a query(), just thought maybe it was something obvious with why AR wasn't giving me rows Tongue
#6

[eluser]bretticus[/eluser]
[quote author="Pale Rider" date="1268439558"]


result just returns one result? What should I be using? I have many queries such as

[/quote]

Check out the example for result() in the manual.
#7

[eluser]Pale Rider[/eluser]
Ahh, thank you sir Big Grin

Just tried FALSE and it worked. I just looked up AR in the user guide, some how I missed

Quote:If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks.

in there.

Thanks for the help! cheers.
#8

[eluser]bretticus[/eluser]
[quote author="Pale Rider" date="1268439784"]Hmm, just tried

Code:
$this->db->where('visitation >', 'NOW()', TRUE);

but no nice.

I guess I can try doing a query(), just thought maybe it was something obvious with why AR wasn't giving me rows Tongue[/quote]

Read my edit above (it should have been FALSE not TRUE.)




Theme © iAndrew 2016 - Forum software by © MyBB