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.
Any help would be appreciated!
Thanks
Rachel