Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » Search date between two dates in search screen
Search date between two dates in search screen [message #1782] Thu, 30 October 2008 11:43 Go to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
I have a 'person' table and would like to filter by birth date, is it possible in the search screen to filter the birth date with something like
between '02/11/1986' and '05/11/1986'
?
I mean, can a date be filtered by ranges?
Re: Search date between two dates in search screen [message #1784 is a reply to message #1782] Thu, 30 October 2008 12:18 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Take a look at FAQ52.

Re: Search date between two dates in search screen [message #1840 is a reply to message #1782] Fri, 14 November 2008 07:08 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
I just tried this, and it doesn't work for me.
In _cm_pre_getData() the two added fields aren't included in $fieldarray.
Also if I put this code in the detail screen:
$structure['main']['fields'][1][] = array('label' => 'Date From');
$structure['main']['fields'][1][] = array('field' => 'date_from');
$structure['main']['fields'][1][] = array('label' => 'To');
$structure['main']['fields'][1][] = array('field' => 'date_to');

the fields don't appear, I had to put this code to show the fields:
$structure['main']['fields'][] = array('label' => 'Date From');
$structure['main']['fields'][] = array('date_from' => 'date_from');
$structure['main']['fields'][] = array('label' => 'To');
$structure['main']['fields'][] = array('date_to' => 'date_to');

[Updated on: Fri, 14 November 2008 07:16]

Report message to a moderator

Re: Search date between two dates in search screen [message #1842 is a reply to message #1840] Fri, 14 November 2008 09:40 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
There are two ways of defining fields in the $structure array:
..['fields'][1][]  // puts all the fields in the same line (line 1 in this example).
..['fields'][]     // puts each field on a separate line.

You are correct in saying that _cm_pre_getData() does not add the two fields to $fieldarray. This is done by code in std.search1.inc.


Re: Search date between two dates in search screen [message #1843 is a reply to message #1782] Fri, 14 November 2008 11:14 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
So what should I do to make this work?

In _cm_pre_getData the tw date fields aren't in $fieldarray, therefore this code is never executed:
	if (!empty($fieldarray['date_from']) OR !empty($fieldarray['date_to'])) {
	    $fieldarray['fecnac'] = rangeFromTo($fieldarray['date_from'], $fieldarray['date_to'], true);
	    unset($fieldarray['date_from']);
	    unset($fieldarray['date_to']);
	} // if


I can see the search fields, but it doesn't filter correctly, are there any working example?

[Updated on: Fri, 14 November 2008 11:17]

Report message to a moderator

Re: Search date between two dates in search screen [message #1844 is a reply to message #1842] Fri, 14 November 2008 11:54 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
AJM wrote on Fri, 14 November 2008 09:40

There are two ways of defining fields in the $structure array:
..['fields'][1][]  // puts all the fields in the same line (line 1 in this example).
..['fields'][]     // puts each field on a separate line.

You are correct in saying that _cm_pre_getData() does not add the two fields to $fieldarray. This is done by code in std.search1.inc.


This
['fields'][1][]
isn't working for me..
Re: Search date between two dates in search screen [message #1845 is a reply to message #1843] Fri, 14 November 2008 12:22 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
bonzo_bcn wrote on Fri, 14 November 2008 16:14

I can see the search fields, but it doesn't filter correctly, are there any working examples?

Yes. In the Radicore system go to Home -> Audit where you will see screen http://www.tonymarston.net/php-mysql/menuguide/audit_dtl(sea rch).html. When you press the SUBMIT button this will pass conrol to screen http://www.tonymarston.net/php-mysql/menuguide/audit_dtl(lis t)2.html. This is where the "date_from" and "date_to" fields are used to construct a value for the "trn_date" field.


Re: Search date between two dates in search screen [message #1846 is a reply to message #1844] Fri, 14 November 2008 12:25 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
bonzo_bcn wrote on Fri, 14 November 2008 16:54

This
['fields'][1][]
isn't working for me..

Then you are doing something wrong. Take a look at the working example above which uses file radicore\audit\screens\en\audit_tbl.detail.screen.inc as its screen structure file.


Re: Search date between two dates in search screen [message #1847 is a reply to message #1782] Fri, 14 November 2008 12:49 Go to previous message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
Ok, looing at the example I found I needed more code:
        if (empty($this->sql_search)) return $where;

        // convert from string to an associative array
        $fieldarray = where2array($this->sql_search, false, false);

	if (!empty($fieldarray['date_from']) OR !empty($fieldarray['date_to'])) {
	    $fieldarray['fecnac'] = rangeFromTo($fieldarray['date_from'], $fieldarray['date_to'], true);
	    unset($fieldarray['date_from']);
	    unset($fieldarray['date_to']);
	} // if
	
	$this->sql_search = array2where($fieldarray);


Everything is working now, thanks.
Previous Topic: How to default values in output4 screen?
Next Topic: Modify $report within the code
Goto Forum:
  


Current Time: Fri Nov 29 18:33:58 EST 2024

Total time taken to generate the page: 0.01437 seconds