how to use criteria()

Discussion specific to symfony 1.1.x stable

Moderator: hartym

how to use criteria()

Postby marvoh » Wed Jun 03, 2009 7:22 am

i'm still in my baby steps in symfony so not so familiar with the criteria object.

anyone care to help me convet the below sql?

select license, count(license), browser, ip, created_on from stats group by license order by count(license) desc
marvoh
Junior Member
 
Posts: 23
Joined: Mon May 11, 2009 8:50 pm
Location: Nairobi

Re: how to use criteria()

Postby Phoelis » Wed Jun 10, 2009 4:50 pm

hmm try this :

Code: Select all
$c = new Criteria();
$c->addGroupByColumn(StatsPeer::LICENSE);
$c->addAsColumn('mycount', ' COUNT( '.StatsPeer::LICENSE.' )');

$myResult= StatsPeer::doSelect($c);
Phoelis
Member
 
Posts: 68
Joined: Sat Mar 01, 2008 1:49 pm
Location: Brussels

Re: how to use criteria()

Postby marvoh » Thu Jun 11, 2009 10:16 am

thanks, had figured that out after a few searches on the internet. now i have an almost same dilema..

i have the following code which works fine on my localhost..
$connection = Propel::getConnection();
$query = "SELECT COUNT(*) AS count FROM stats WHERE license LIKE '".$param1."' AND MONTH(created_on) = '".$param2."'";
$statement = $connection->prepareStatement(sprintf($query, StatsPeer::TABLE_NAME));
$resultset = $statement->executeQuery();
$resultset->next();
return $resultset->getInt('count');

and evaluates to the following sql: SELECT COUNT(*) AS count FROM stats WHERE license LIKE 'LC1234' AND MONTH(created_on) = '6'

however, on the webserver, the query is a little different thus making it not run, here's the sql: SELECT COUNT(*) AS count FROM stats WHERE license LIKE 'LC1234' AND MONTH('stats.CREATED_ON') = '6'

where are these quotes ('stats.CREATED_ON') coming from..
marvoh
Junior Member
 
Posts: 23
Joined: Mon May 11, 2009 8:50 pm
Location: Nairobi

Re: how to use criteria()

Postby marvoh » Fri Jun 12, 2009 8:32 am

im trying to use propel to solve the above issue:
here's my sql:
SELECT COUNT(*) AS count FROM %s WHERE browser LIKE '".$param1."' AND MONTH(created_on) = '$param2'

then here's my code using criteria object
$c = new Criteria();
$c->addAsColumn('hits', 'MONTH(created_on)');
$c->add(StatsPeer::LICENSE_ID, $param1, CRITERIA::LIKE );
$c->add('hits', $param2, CRITERIA::EQUAL );
return StatsPeer::doCount($c);

this evaluates to something totally different. hope it wont take ages to get help like it usually does here otherwise i will be time barred
marvoh
Junior Member
 
Posts: 23
Joined: Mon May 11, 2009 8:50 pm
Location: Nairobi

Re: how to use criteria()

Postby halfer » Wed Jun 17, 2009 5:46 pm

hope it wont take ages to get help like it usually does here

Problem is, I read that phrase and am put off helping you straight away. We do have the problem on the fora that the ratio of requests to respondents is not good, and also the core developers are pushing the mailing list groups in favour of this forum system. But nevertheless, I do recommend that you should be careful how you ask for assistance!
halfer
Faithful Member
 
Posts: 10148
Joined: Mon Jan 30, 2006 1:16 pm
Location: West Midlands, UK

Re: how to use criteria()

Postby ktoso » Tue Jun 30, 2009 9:17 pm

Might be usefull in learning to build propper propel queries: http://propel.jondh.me.uk/
"Life is Study!" - Kintaro Oe
ktoso
Member
 
Posts: 33
Joined: Tue Feb 03, 2009 2:14 am
Location: Poland


Return to symfony 1.1

Who is online

Users browsing this forum: No registered users and 1 guest