createdDate Search Problems

12 posts by 4 authors in: Forums > CMS Builder
Last Post: April 10, 2012   (RSS)

Hello, All

This is an interesting one...

I've started having problems with date searches using the createdDate field. (NB: This never used to be the case so can only assume it has cropped up now due to some recent update.)

The format I use is typically...

./index.php?category=5&createdDate_year=2013

Until recently this always worked without fail. But now something seems to be broken.

Certain dates are causing problems. The result is that although the search works (and returns the correct records) a completely unrelated getRecords() call (on the same page) fails.

The problem appears to be completely inconsistent. One date will work - but another one won't.

It's very odd!

In an attempt to make sense of the problem I ran similar searches (using the same dates) but using the date_year format.

This time there were no problems.

It occurs to me that the only difference between the createdDate and the date fields is that the latter does not store the time. Could this - somehow - be the cause of the search problems?

:0/

Perch

Re: [Perchpole] createdDate Search Problems

By Jason - February 24, 2012

Hi Perch,

So the section that you want to search on using createdDate always works, and a different getRecords call works some of the time. Is that right?

My first guess is that the second call is also being filtered by createdDate, since this is a field common to all sections. Try adding

'allowSearch' => false,

to the second query.

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: [Jason] createdDate Search Problems

Hi, Jason -

You are absolutely right.

There are a number of getRecords calls on the page that were failing to execute - but since adding the 'allowSearch' => false, code all seems to be back to normal.

Can you explain what's happening here and why the problem only occurs with createdDate and not date searches.

:0/

Perch

Re: [Jason] createdDate Search Problems

Hi, Jason -

Thanks for this - but let me just get something straight...

If I add "any" code to a URL I am effectively running a search?

Is that right?

Say my URL is: www.perchpole.com

But if I add make it: www.perchpole.com?category=7

Now CMSB handles this as a search?

:0)

Perch

Re: [Perchpole] createdDate Search Problems

By Jason - February 27, 2012

Hi Perch,

That's right. Any time there is a variable in your URL that matches a field name in a section you're using getRecords on, the value of that variable ends up in the search.

So in your example, if you were getting records from a section that had a category field, getRecords would only return records where category had a value of 7.

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: [Jason] createdDate Search Problems

By nmsinc - April 7, 2012

[font "Times New Roman"]Hi Jason,[/#000000]

[font "Times New Roman"] [/#000000]

[font "Times New Roman"]I have a search form that requires a search across multiple sections and fields. However, I need it only to search one section for the createdDate field. How can I code the ‘allowSearch’ function to only remove or allow specific fields?[/#000000]

[font "Times New Roman"] [/#000000]

[font "Times New Roman"]Thanks - nmsinc[/#000000]
nmsinc

Re: [nmsinc] createdDate Search Problems

By Jason - April 9, 2012

Hi,

To actually change the way that getRecords() actually dynamically creates a WHERE clause, you would need to change the source code of that function. Although you can give this a try, it is definitely not recommended.

If you are submitting multiple search fields for your search, and only want certain fields searched on certain sections, your best bet would be to disable the automatic search and manually create your own WHERE clauses.

For example, if you have a news section where you wanted to search on createdDate only, you could use this:

EXAMPLE:

list($newsRecord, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'allowSearch' => false,
'where' => "`createdDate` LIKE '".mysql_escape(@$_REQUEST['createdDate'])."%'",
));


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: [Jason] createdDate Search Problems

By nmsinc - April 9, 2012

Hi Jason,

I need to block the createdDate from two out of three sections while still searching the remaining fields in all sections so this option will not work. Any other suggestions?

Thanks - nmsinc
nmsinc

Re: [nmsinc] createdDate Search Problems

By Jason - April 9, 2012

Hi,

One option would be to temporarily destroy any $_REQUEST variables you don't want searched just before the call and then reinstating it right after the call.

For example, if you had a news section where you didn't want to search against the createdDate field:

EXAMPLE:


//temporarily store createdDate
$tmpcreatedDate = $_REQUEST['createdDate'];
unset($_REQUEST['createdDate']);

list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
));

//reinstate createdDate
$_REQUEST['createdDate'] = $tmpcreatedDate;


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/