Jump to:

11004 Posts in 2735 Topics by 1824 members

All other Modules

SilverStripe Forums » All other Modules » sql query select fields

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 307 Views
  • tim32
    Community Member
    2 Posts

    sql query select fields Link to this post

    Hi all,

    I am working on my website called belminuten.net.
    I have created a custom page that does a query for data. Please find the code below.

    $sqlQuery = new SQLQuery();
    $sqlQuery->selectField('id', 'id');
    $sqlQuery->selectField('abo_type', 'abo_type');
    $sqlQuery->selectField('abo_minutes', 'abo_minutes');
    $sqlQuery->selectField('abo_sms', 'abo_sms');
    $sqlQuery->selectField('abo_data', 'abo_data');
    $sqlQuery->selectField('abo_time', 'abo_time');
    $sqlQuery->selectField('abo_price', 'abo_price');
    $sqlQuery->addWhere('provider = \''.$this->brand.'\'');

    $result = $sqlQuery->execute();

    It works great, but when i check the full query with
    echo $sqlQuery->sql();

    I get:
    SELECT *, id, abo_type, abo_minutes, abo_sms, abo_data, abo_time, abo_price, img, CONCAT(abo_time,'_',abo_minutes,'_',abo_data) AS "slug" FROM simonly_abo WHERE (provider = 'aess44') GROUP BY slug ORDER BY abo_price ASC

    I only need the fields I selected, but silverstripe puts * at the beginning of the query. How can I prevent this from happening?


    UPDATE: i figured it out. I used setSelect() instead of selectField(). that solved the problem.

  • Pigeon
    Community Member
    243 Posts

    Re: sql query select fields Link to this post

    It's because the default value when you construct the object is *

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.