Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Nedeľa, 29. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Specifying a date range for a query

phpMyEdit Features     Specifying a date range for a query
Odoslať novú tému   Odpovedať na tému    
 
Amit     Založený: 16.05.2004   Príspevky: 22  
Príspevok Zaslal: 2004-05-18 11:35
Návrat hore  Odpovedať s citátom     

At the moment I can only use >= or <= for my queries where 'select' = 'N'. Anyway that I can get a range for dates? I want to find all records within a specific date range.

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2004-05-19 10:19
Návrat hore  Odpovedať s citátom     

afaik there is no 'nicer' way...

you can emulate this with 'filters' option and custom buttons.

see also 'custom filters' bellow in this forum

 
ajh     Založený: 17.12.2003   Príspevky: 236  
Príspevok Zaslal: 2004-05-20 09:20
Návrat hore  Odpovedať s citátom     

I haven't tried it, but MySQL has a BETWEEN operator - it should work for dates as well. Ie, you should be able to say:

BETWEEN '2004/01/01' AND '2004/02/01'

 
Amit     Založený: 16.05.2004   Príspevky: 22  
Príspevok Zaslal: 2004-06-14 14:14
Návrat hore  Odpovedať s citátom     

ajh Napísal:
I haven't tried it, but MySQL has a BETWEEN operator - it should work for dates as well. Ie, you should be able to say:

BETWEEN '2004/01/01' AND '2004/02/01'


Thanks for this suggestion. It works if I create a new PHP file and write a query but if I try the following it fails:
Citácia:
$opts['fdd']['Date'] = array(
'name' => 'Date',
'select' => 'N',
'maxlen' => 10,
'default' => '0000-00-00',
'required' => true,
'sort' => true
);
$opts['fdd']['Date']['values']['filters'] = 'Date BETWEEN $from_date AND $to_date';


 
Amit     Založený: 16.05.2004   Príspevky: 22  
Príspevok Zaslal: 2004-06-17 15:22
Návrat hore  Odpovedať s citátom     

I tried the following as well and it did not work.
Citácia:
$opts['filters'] = "Date >= $from_date AND Date <= $to_date";

I am stuck!

 
Amit     Založený: 16.05.2004   Príspevky: 22  
Príspevok Zaslal: 2004-06-18 14:35
Návrat hore  Odpovedať s citátom     

doug Napísal:
I've also been unsuccesful in trying to achieve similar filters. Perhaps the answer is to write a PHP script that creates a HEAP table (MySQL temporary table) populated with the appropriate dates, and then connect the HEAP table to a phpMyEdit form ???
http://opensource.platon.sk/forum/projects/viewtopic.php?t=395&highlight=temperary+temporary+table


Thanks. Will try that. Does anyone have another suggestion?

 
Amit     Založený: 16.05.2004   Príspevky: 22  
Príspevok Zaslal: 2004-06-19 02:36
Návrat hore  Odpovedať s citátom     

doug Napísal:
I've also been unsuccesful in trying to achieve similar filters. Perhaps the answer is to write a PHP script that creates a HEAP table (MySQL temporary table) populated with the appropriate dates, and then connect the HEAP table to a phpMyEdit form ???
http://opensource.platon.sk/forum/projects/viewtopic.php?t=395&highlight=temperary+temporary+table


Doug, do you have an example I could use? Thanks for your help.

 
Amit     Založený: 16.05.2004   Príspevky: 22  
Príspevok Zaslal: 2004-06-19 11:04
Návrat hore  Odpovedať s citátom     

I think I have found the source of the problem:
Citácia:
$opts['filters'] = "Date BETWEEN '2002-04-01' AND '2003-01-01'";

works if I use the main Class (latest 1.143 version from CVS) or the Reports Extension.
But this filter does not work if I use variables in Report Class.
Citácia:
"Date BETWEEN '$from_date' AND '$to_date'"

Possible cause : There is a problem in my form capture being picked up and transferred to the variables for the filter (see):

The form capture is :
Citácia:
http://127.0.0.1/~juneja/phpmyedit-5.4/displayreport.php?
have_Name=on&qf0_id=Vedanta&have_Reference=on&have_Date=on
&have_DebitAccount=on&have_CreditAccount=on&have_Currency=on
&qf5_id=%2A&have_Amount=on&have_Description=on
&have_ChequeNumber=on&have_AccountNumber=on&qf9_id=%2A
&book=Cashbook&from_date=1980-01-01&to_date=2010-12-31
&inc=0&filter=Make%20report&inc=0&have_Name=on
&have_Reference=on&have_Date=on&have_DebitAccount=on
&have_CreditAccount=on&have_Currency=on&have_Amount=on
&have_Description=on&have_ChequeNumber=on
&have_AccountNumber=on


but somewhere the variables are getting zeroised and therefore the filter does not work.

Anyone has a nice and easy way to capture data on the form and have it used as the filter variables?

The bold items are the form captured data.

 
Amit     Založený: 16.05.2004   Príspevky: 22  
Príspevok Zaslal: 2004-06-21 01:08
Návrat hore  Odpovedať s citátom     

doug Napísal:
How to you get a value from the SELECT box option <option>Cashbook</option> when no value is set?


How do I set the value? Are you referring to the following code?

Kód:
            $headers_sent || setcookie($varname.'_'.$this->tb.'_cookie', '', time() - 10000);
         }
      }
         

            $book = $HTTP_POST_VARS[book];
            $from_date = $HTTP_POST_VARS[from_date];
            $to_date = $HHTP_POST_VARS[to_date];



      $i = -1;
      foreach (array_keys($this->fdd) as $key) {
         $i++;
         if (preg_match('/^\d*$/', $key))

See the part where $book gets the value from $HTTP_POST_VARS. This section appears in the report extnesion. If this is not right can you show me how to set the value. Thanks again

 
Amit     Založený: 16.05.2004   Príspevky: 22  
Príspevok Zaslal: 2004-06-24 15:32
Návrat hore  Odpovedať s citátom     

Doug, please let me reframe my problem -

I need to set the filter to work using variables instead of values:

Kód:
$opts['filters'] = "Date BETWEEN '2002-01-01' AND '2003-12-31'"; //this works beautifully!!!


but if i try to do:
Kód:
$opts['filters'] = "Date BETWEEN $from_date AND $to_date";


I get:
Citácia:
MySQL error 1064
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND ) ORDER BY PMEtable0.Date,PMEtable0.Name' at line 1

phpMyEdit error: invalid SQL query
SELECT PMEtable0.Name AS qf0,PMEtable0.Name AS qf0_idx,PMEtable0.Reference AS qf1,PMEtable0.Date AS qf2,PMEtable0.Date AS qf2_idx,PMEtable0.DebitAccount AS qf3,PMEtable0.DebitAccount AS qf3_idx,PMEtable0.CreditAccount AS qf4,PMEtable0.CreditAccount AS qf4_idx,PMEtable0.Currency AS qf5,PMEtable0.Currency AS qf5_idx,PMEtable0.Amount AS qf6,PMEtable0.Description AS qf7,PMEtable0.ChequeNumber AS qf8,PMEtable0.AccountNumber AS qf9,PMEtable0.AccountNumber AS qf9_idx FROM business AS PMEtable0 WHERE PMEtable0.Name = 'Vedanta' AND (Date BETWEEN AND ) ORDER BY PMEtable0.Date,PMEtable0.Name


How can I get a filter to accept variables?

After reading one of the posts here tried the following:
Kód:
$opts['filters'] = $daterange;


and added the following for the capture of the query:
Kód:
      echo 'From Date: ';
      echo '<input class="',$css_class_name,'" type="date" size = "10" name="fromdate" value="',$this->fromdate.'">';
   
      echo 'To Date: ';
      echo '<input class="',$css_class_name,'" type="date" size = "10" name="todate" value="',$this->todate.'">';
      echo '</td></tr>',"\n";

      $daterange = "Date BETWEEN ".$this->fromdate." AND ".$this->todate;


I got rid of the MySQL error but the filter did not get work. I got all the records.

Any suggestions on the above?


Naposledy upravil Amit dňa 2004-06-24 15:54, celkom upravené 1 krát

 
Amit     Založený: 16.05.2004   Príspevky: 22  
Príspevok Zaslal: 2004-06-24 16:11
Návrat hore  Odpovedať s citátom     

Thanks Doug, I tried your suggestion and got rid of the MySQL error. The query works but no fields are pciked up because both "from date" and "to date" are 0 so the BETWEEN clause picks up no records (the range is between 0 and 0!).

Is there an error in my pickup of the values from the form:
Kód:
      echo 'From Date: ';
      echo '<input class="',$css_class_name,'" type="date" size = "10" name="fromdate" value="',$this->fromdate.'">';
   
      echo 'To Date: ';
      echo '<input class="',$css_class_name,'" type="date" size = "10" name="todate" value="',$this->todate.'">';
      echo '</td></tr>',"\n";

      $from_date = 'fromdate';
      $to_date = 'todate';


Alternative:
As an alternative I saw one of posts and tried the following:
Kód:
$opts['filters'] = $daterange;


and for the capture of the query:
Kód:
      echo 'From Date: ';
      echo '<input class="',$css_class_name,'" type="date" size = "10" name="fromdate" value="',$this->fromdate.'">';
   
      echo 'To Date: ';
      echo '<input class="',$css_class_name,'" type="date" size = "10" name="todate" value="',$this->todate.'">';
      echo '</td></tr>',"\n";

      $daterange = "Date BETWEEN ".$this->fromdate." AND ".$this->todate;


But in this case a different problem the filter does not get triggered and therefore I see all the records.

What's the best way out of this?[/b]

 
Amit     Založený: 16.05.2004   Príspevky: 22  
Príspevok Zaslal: 2004-06-26 11:39
Návrat hore  Odpovedať s citátom     

doug Napísal:
I'm confused, out of ideas ... maybe wait for an enhanced version of the class file.


I fixed it Doug -

Citácia:
$book = $_GET[book];
if ($book == 'Cashbook')
{$book = 'Cash';}
elseif ($book == 'Bank')
{$book = 'Bank';}
$from_date = $_GET[fromdate];
$to_date = $_GET[todate];


Add to this the following filters code -
Kód:
$acc = "DebitAccount = '".$book."' OR CreditAccount = '".$book."'";
$daterange = "Date BETWEEN '".$from_date."' AND '".$to_date."'";
$opts['filters'] = "(".$acc.") AND ".$daterange;


and voila it works! if you have a cleaner way I would be happy to change the coding.

Thanks for your help!

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov