Forum Moderators: coopster

Message Too Old, No Replies

date evaluation in flat file db

         

lucesei

2:17 am on Jul 1, 2004 (gmt 0)

10+ Year Member



I'm writing a search function that will go through a flat file db looking for a date interval and will return all entries that match that date interval.
I have the following code:


$date_from = mktime(0,0,0,$from_date_month,$from_date_day,$from_date_year);
$date_to = mktime(0,0,0,$to_date_month,$to_date_day,$to_date_year);

if (file_exists("../data/textdb.php")) {
$Data = file("../data/textdb.php");
$c = 0;
foreach($Data as $Line) {
list($entrydate,$userName,$userEmail) = explode("¦", $Line);}
$entrydate = trim($entrydate);
if($entrydate > $date_from && $entrydate < $date_to) {
$entrydate[$c] = strtok($Line,"¦");
$userName[$c] = strtok("¦");
$userEmail[$c] = strtok("¦");
$c++;
}
}
}

And then goes on to echo the results...PROBLEM? It echoes NOTHING. What am I doing wrong? Can anyone help me? Is there another way to search for a time interval?

Thanks so much for your help.

Birdman

3:07 am on Jul 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you may need to rename the arrays you are storing the matches in. Also, you shouldn't need to use strtok(), since the data was already exploded. Looks like there was an extra closing bracket(}) after the semicolon in the list() line as well.

Here's how I would do it:

if ( $Data = @file("../data/textdb.php") ) {
foreach($Data as $Line) {
$fields = explode("¦", $Line);
$date = trim($fields[0]);
if($date > $date_from && $date < $date_to) {
$entrydate[] = $fields[0];
$userName[] = $fields[1];
$userEmail[] = $fields[2];
}
}

You don't need to use a counter to set the array indexes. If you leave the brackets blank, they increment automatically. Hope it works for ya.

Birdman