Markie
Posts: 251
|
| Posted: 01/12/2009, 1:27 PM |
|
I would like to have a listbox with which I can select uploaded files during periods.
For example:
search maximum age:
all ages
from last 7 days
from last 14 days
from last 21 days
from last 30 days
from last 60 days
from last 90 days
from last 120 days
In my table, I have a timestamp field (GeneralDate, dbformat yyyy-mm-dd HH:nn:ss)
Is it possible to make such a select box ?
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
damian
Posts: 838
|
| Posted: 01/12/2009, 6:53 PM |
|
i reckon you probably could... let me have a try....
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
damian
Posts: 838
|
| Posted: 01/13/2009, 5:37 AM |
|
beats me - but i would like to see how its done...
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
maxhugen
Posts: 272
|
| Posted: 01/13/2009, 2:52 PM |
|
Are you using a Search form plus Grid (results) ?
If you are, the listbox (in the Search form) values would be 7, 14, 21 ....
In your Grid query, create a calculated field producing days elapsed from Now(). This field can then be used to compare to the value passed by the listbox.
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com |
 |
 |
Markie
Posts: 251
|
| Posted: 01/14/2009, 2:48 AM |
|
Hi maxhugen, I understand what you mean. I do use a search form plus grid on the same page. Making the listbox with the values is easy, but understanding how to create the calculated field producing days elapsed from Now() is not.
With VQB I can make something like this:
SELECT *
FROM table
WHERE ( Timestamp >= DATE_SUB(NOW(),INTERVAL 1 DAY) )
ORDER BY Timestamp desc
which produces this code:
function Prepare()
{
global $CCSLocales;
global $DefaultDateFormat;
$this->wp = new clsSQLParameters($this->ErrorBlock);
$this->wp->AddParameter("1", "expr48", ccsMemo, "", "", $this->Parameters["expr48"], "", false);
$this->wp->Criterion[1] = $this->wp->Operation(opContains, "Basename", $this->wp->GetDBValue("1"), $this->ToSQL($this->wp->GetDBValue("1"), ccsMemo),false);
$this->wp->Criterion[2] = "( Timestamp >= DATE_SUB(NOW(),INTERVAL 1 DAY) )";
$this->Where = $this->wp->opAND(
false,
$this->wp->Criterion[1],
$this->wp->Criterion[2]);
}
Is this the right way to go ? Is it possible to connect this query to the listbox ? How can I change INTERVAL 1 DAY into the intervals of the listbox ?
Anybody ?
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
mentecky
Posts: 321
|
| Posted: 01/14/2009, 11:57 PM |
|
Markie,
I'd probably create a list box in the search form, ie "s_interval", and set the values to something like:
Value=1 Text=1 day
Value = 7 Text =1 week
...
Build your query on your grid to show all items and ignore the "s_interval" param. Then in your grid's "Before Build Select" event add something like:
$interval = CCGetParam("s_interval", -1);
// Don't add if s_interval was not a param
if ($interval != -1)
{
$where = $Component->ds->Where;
// If the where clause isn't empty add "AND" to it
if (strlen($where))
{
$where.= " AND ";
}
$where .= "Timestamp >= DATE_SUB(CURDATE(), INTERVAL $interval DAY)";
$Component->ds->Where = $where;
}
Hope that helps,
Rick
_________________
http://www.ccselite.com |
 |
 |
Markie
Posts: 251
|
| Posted: 01/15/2009, 9:21 AM |
|
It's working now and I have one question left:
When I use the listbox to search the results for, let's say, 1 week and I search, the page refreshes to show the results. Now, the listbox has also been automatically refreshed and shows the first option in the listbox again. This is a bit confusing.
I want the listbox to show the last selected option again, the option that has been selected before the page refreshed. This last selection is available in the url, so I suppose this has to be possible.
What's the solution for this ?
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
mentecky
Posts: 321
|
| Posted: 01/15/2009, 11:44 PM |
|
Markie,
I'm not sure why it's not defaulting. Did you try setting the listbox's default value to something like:
CCGetParam("s_interval","")
Rick
_________________
http://www.ccselite.com |
 |
 |
|