Where clause not working as would be expected

2 posts by 2 authors in: Forums > CMS Builder
Last Post: October 23, 2009   (RSS)

By garyhoffmann - October 23, 2009

Hi,

I'm trying to use a custom where clause. A pretty simple one at that and it's not returning any records.

Here is the code:

$mydate=getdate(time());
list($sidebarRecords, $sidebarMetaData) = getRecords(array(
'tableName' => 'daily_specials',
'limit' => '1',
'where' => "title= '".$mydate['weekday'] . "' ",
));

$sidebarRecord=$sidebarRecords[0];


So, today (Friday), this would have an effect of "title= 'Friday'" in the where clause.

I do have a record in the "daily_specials" table with a title of Friday, so this should be picking up that record.

On the line $sidebarRecord=$sidebarRecords[0]; I'm getting an error that [0] is an invalid offset.

Any pointers as to what might be wrong would be helpful.

Thanks,
Gary.

Re: [garyhoffmann] Where clause not working as would be expected

By Chris - October 23, 2009

Hi Gary,

That code looks correct to me. I don't have any ideas other than to simplifying matters to narrow down where the problem is. For example, you could try to hardcode "Friday":

list($sidebarRecords, $sidebarMetaData) = getRecords(array(
'tableName' => 'daily_specials',
'limit' => '1',
'where' => "title= 'Friday' ",
));
$sidebarRecord=$sidebarRecords[0];


Assuming that doesn't work either, you could check your record's title field to make sure it doesn't have a trailing space, incorrect capitalization, or anything else strange.

You could also try using the built-in search feature of a list page to make sure exampleList.php?title=Friday shows your record.

If you still can't figure out what's wrong, let me know.
All the best,
Chris