where clause is ignored

4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 4, 2010   (RSS)

By mdegive - November 4, 2010 - edited: November 4, 2010

I removed the 'where' => whereRecordNumberInUrl(1),
but it still includes it.
I added a 'where' => 'num=1',
and it still includes it.

here is the code:
list($orderRecords, $orderMetaData) = getRecords(array(
'tableName' => 'report_order',
'where' => 'num=1',
'debugSql' => true,
));
$orderRecord = $orderRecords[0]; // get first record

and here is the sql it generated:
SELECT SQL_CALC_FOUND_ROWS `report_order`.* FROM `cms_report_order` as `report_order` WHERE (num=1 AND (`num` = '2'))

Version 2.06. This is a single menu type

Help!

Re: [mdegive] where clause is ignored

By Jason - November 4, 2010

Hi,

You're "where" clause isn't being ignored, but it is being appended. There is probably something in your query string like num=2 or 2 being the last number in your query string and that's where this number is coming from.

You can get around this by setting allowSearch to false like this:

list($orderRecords, $orderMetaData) = getRecords(array(
'tableName' => 'report_order',
'where' => 'num=1',
'allowSearch' => false,
));
$orderRecord = $orderRecords[0]; // get first record


Also, if this is a single record section, there isn't any need for a where clause at all, there will only ever be one record, so you could also change it to this:

list($orderRecords, $orderMetaData) = getRecords(array(
'tableName' => 'report_order',
'allowSearch' => false,
));
$orderRecord = $orderRecords[0]; // get first record


This will just get the first record for that section. Since there is only 1, it will always be the first one.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [mdegive] where clause is ignored

By Jason - November 4, 2010

Hi,

It depends on what is in the query string. If a variable name in the query string matches a field in a section you're searching(like num), it will automatically add that to the where clause. Turning off allowSearch will prevent it from doing this.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/