To check for date and then retrive the contents

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Rachel
Forum Newbie
Posts: 1
Joined: Tue Jul 21, 2009 11:22 am

To check for date and then retrive the contents

Post by Rachel »

Hey

I'm working as Software Developer. Mostly I'm on the php side. Recently working on a project with a csv file where I need to retrieve the contents of file with date, title and panel in a table format.


I was able to do the table format and also retrieving the data with title and panel. Now one major issue is with the date. Let's say I have a html file for entering date, title and panel.

so here's the code I have worked so far

Code: Select all

<?php
 
//$_POST variable for the html file  
 
$from = $_POST['fdate'];
$to = $_POST['tdate'];
$title = $_POST['sd'];
$panel = $_POST['dropbx'];
 
//log files (csv ) contained in an array
$array_files = array("_play_log.csv","_play1_log.csv","...");
 
//check whether file exists in an array
$g = 0;
if(in_array($array_files[$g], $array_files))
{
 
//if it exists get the contents of the file
$data = "";
 for($l = 0 ; $l < count($array_files); $l++)
{
 
$data .= file_get_contents($array_files[$l]);
 
}
$new = split("\r", $data);
 
//convert the date to UNIX timestamp
$fromdate = strtotime($from);
$todate = strtotime($to);
 
$currentdate = $fromdate;
 
//read the csv file contents into an array using foreach loop
$q = 0;
foreach($new as $line)
{
 
$date[$q] = split(",", $line);
 
//checks for currentdate entered and loops till the todate
for($m = $currentdate; $m <= $todate; $m += (60*60*24)){
 
//checks if it's current date & title &panel
if($fromdate == $m && $title == $date[$q][1] || $title == ""){
if($fromdate == $m && $panel == $date[$q][2] || $panel == ""){
 
 
 
 
//echo's out the content if true
 
echo $date[$q][0].",".$date[$q][1].",".$date[$q][2];
echo "<br>";
 
}
 
}
 
}
$q++;
 
}
$g++;
 
}
?>
 


csv file would look something like this:

Date-time,Title,Panel,Filename,Duration
2009/07/01 16:20:25,top,panel4,panel4/slide,5
..........................................
...........................................
.......................................


so if the date entered in the from column ( html page ) is 2009/07/01 and it's title is top and panel is panel4, it has to retrieve the contents. If the date entered doesn't match up it should not display anything.
:( The problem here is any date I enter it retrieves the contents of the file. Which should not be the case.

:banghead: Also I have multiple files and not just one.

Any help would be appreciated!

Thanks
Rachel
Last edited by Rachel on Wed Jul 22, 2009 1:13 pm, edited 2 times in total.
spider.nick
Forum Commoner
Posts: 72
Joined: Wed Jul 15, 2009 12:22 pm
Location: Overland Park, KS

Re: To check for date and then retrive the contents

Post by spider.nick »

Rachel:

Please surround your code with the proper code=php tags.

Nick
Post Reply