Propel $criteria->addAsColumn(“lastRow”,MAX(self::ID)) error

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
helloise
Forum Commoner
Posts: 31
Joined: Tue Sep 21, 2010 4:20 am

Propel $criteria->addAsColumn(“lastRow”,MAX(self::ID)) error

Post by helloise »

i have this code:

Code: Select all

static public function getLastNewMessage($profile_id)
    {
        $c = new Criteria();
        $subSelect = "rc_message_box_table.profile_id_from NOT IN ( SELECT rc_blocklist_table.profile_id_block   FROM  rc_blocklist_table	WHERE  profile_id = $profile_id  ) and rc_message_box_table.profile_id_to=$profile_id and opened_once = 0";
        $c->add(self::PROFILE_ID_TO, $subSelect, Criteria::CUSTOM);
        $c->addAsColumn("lastRow", MAX(self::ID));
        //$subSelect2 = "max(rc_message_box_table.id)";
        //$c->add(self::ID, $subSelect2, Criteria::CUSTOM);
        return self::doSelect($c);
    }
but get error: 500 | Internal Server Error | PropelException [wrapped: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS lastRow FROM rc_message_box_table` WHERE rc_message_box_table.profile_id_fro' at line 1]

i also tried the commented out lines and it is not working
i just want the record of MAX(auto-increment-field) on the rc_message_box_table and this field is ID i have tried the commented out lines as well but nothing works. i dont know how to achieve this..please help? thank you
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Propel $criteria->addAsColumn(“lastRow”,MAX(self::ID)) e

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
Post Reply