Welcome Guest, Not a member yet? Register   Sign In
Syntax Question for Counting Results?
#1

[eluser]Solarpitch[/eluser]
Hi,

Just wondering if this Syntax is correct. Its just that if I put this into phpmyadmin I get the correct result of 40 being returned.

Code:
SELECT count(type) from sales where tpe = 'cash' and date = $yesterday;

However when I run it like this from my model, I just get 0. So im just wondering if the sql in the model will produce the above? I'm sure there's a way to print the SQL query to screen from the model?

Code:
function yesterday_cash_sales()
{

$yesterday = date('Ymd', mktime(0, 0, 0, date("m") , date("d") - 1, date("Y")));
      
$this->client->like('type');
$this->client->get_where('sales', array('type' => 'cash', 'date' => $yesterday));

$row = $this->client->count_all_results();
        
return $row;
}
#2

[eluser]Solarpitch[/eluser]
Actually..

this seemed to be the answer...

Code:
function yesterday_cash_sales()
    {  
        $this->client->like('type');
        $this->client->from('sales');
        $this->client->where(array('type' => 'cash', 'date' => $this->yesterday));

        return $this->client->count_all_results();

    }

Seems I was using the get_where() incorrectly.




Theme © iAndrew 2016 - Forum software by © MyBB