mobimad
10-15-2009, 03:08 PM
Hi,
I hope someone can help me out, this script gathers infomation from a flat text file and displays it within a table, but i would like to have the dates field displayed in Date Time order, but i just cant get it to work.
Dates are presented like this: October 15 2009, 08:21
Please Help.
Jenna X
Script below:
<?php
$sortby = $_SERVER['QUERY_STRING'];
$set = '';
if ($sortby == '') {
$header = 'Date';
$sortby = 'date';
$set = 'y';
}
if ($sortby == 'network') {
$header = 'Network';
$set = 'y';
}
if ($sortby == 'userID') {
$header = 'UserID';
$set = 'y';
}
if ($sortby == 'sale') {
$header = 'Sale';
$set = 'y';
}
if ($sortby == 'saleID') {
$header = 'SaleID';
$set = 'y';
}
if ($sortby == 'content') {
$header = 'Content';
$set = 'y';
}
if ($sortby == 'site') {
$header = 'Site';
$set = 'y';
}
if ($set == '') {
echo 'The variable at the end of the web address did not match one required by the code. Please check the web address for errors.';
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled</title>
<style type="text/css">
<!--
body, th, td, p, small {
font-family:'Arial';
font-size:10;
color:#000000;
text-align: center;
}
small {font-size:10;}
table {
border:1px solid #ccf;
padding:3px;
}
td, th {
background-color:#FFFFFF;
padding:7px 20px 7px 20px;
}
th {background-color:#E9D2FF; color:#000000;}
h1 {font-size:10; color:#000000;}
h1 .sortby {color:#000000;}
.style1 {color: #000000}
body,td,th {
color: #000000;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
}
body {
background-color: #FFFFFF;
}
a:link {
color: #360051;
}
a:visited {
color: #360051;
}
a:hover {
color: #360051;
}
a:active {
color: #360051;
}
.style2 {color: #000000; font-size: 16px; }
-->
</style>
</head>
<body>
<div align="center">
<?php
echo '
<table summary="List of demo fields">
<tr>
<th><a href="?">Date[/url]</th>
<th><a href="?network">Network[/url]</th>
<th><a href="?userID">UserID[/url]</th>
<th><a href="?sale">Sale[/url]</th>
<th><a href="?saleID">SaleID[/url]</th>
<th><a href="?content">Content[/url]</th>
<th><a href="?site">Site[/url]</th>
</tr>';
$fp = fopen('logs.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
while (!feof($fp)) {
$line = fgets($fp,1024); //use 2048 if very long lines
$row++;
list ($date, $network, $userID, $sale, $saleID, $content, $site) = split ('\|', $line);
if ($sortby == 'date') $sortkey = strtotime($Date);
if ($sortby == 'network') $sortkey = strtolower($Network);
if ($sortby == 'userID') $sortkey = strtolower($UserID);
if ($sortby == 'sale') $sortkey = $Sale;
if ($sortby == 'saleID') $sortkey = strtolower($SaleID);
if ($sortby == 'content') $sortkey = strtolower($Content);
if ($sortby == 'site') $sortkey = $Site;
$col[$row] = array($sortkey, $date, $network, $userID, $sale, $saleID, $content, $site);
}
fclose($fp);
sort($col);
reset ($col);
$arrays = count($col) - 1;
$loop = -1;
while ($loop < $arrays) {
$loop++;
echo '
<tr>
<td>'.$col[$loop][1].'</td>
<td>'.$col[$loop][2].'</td>
<td>'.$col[$loop][3].'</td>
<td>'.$col[$loop][4].'</td>
<td>'.$col[$loop][5].'</td>
<td>'.$col[$loop][6].'</td>
<td>'.$col[$loop][7].'</td>
</tr>';
}
echo '
</table>
' ?>
</div>
</body>
</html>
I hope someone can help me out, this script gathers infomation from a flat text file and displays it within a table, but i would like to have the dates field displayed in Date Time order, but i just cant get it to work.
Dates are presented like this: October 15 2009, 08:21
Please Help.
Jenna X
Script below:
<?php
$sortby = $_SERVER['QUERY_STRING'];
$set = '';
if ($sortby == '') {
$header = 'Date';
$sortby = 'date';
$set = 'y';
}
if ($sortby == 'network') {
$header = 'Network';
$set = 'y';
}
if ($sortby == 'userID') {
$header = 'UserID';
$set = 'y';
}
if ($sortby == 'sale') {
$header = 'Sale';
$set = 'y';
}
if ($sortby == 'saleID') {
$header = 'SaleID';
$set = 'y';
}
if ($sortby == 'content') {
$header = 'Content';
$set = 'y';
}
if ($sortby == 'site') {
$header = 'Site';
$set = 'y';
}
if ($set == '') {
echo 'The variable at the end of the web address did not match one required by the code. Please check the web address for errors.';
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled</title>
<style type="text/css">
<!--
body, th, td, p, small {
font-family:'Arial';
font-size:10;
color:#000000;
text-align: center;
}
small {font-size:10;}
table {
border:1px solid #ccf;
padding:3px;
}
td, th {
background-color:#FFFFFF;
padding:7px 20px 7px 20px;
}
th {background-color:#E9D2FF; color:#000000;}
h1 {font-size:10; color:#000000;}
h1 .sortby {color:#000000;}
.style1 {color: #000000}
body,td,th {
color: #000000;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
}
body {
background-color: #FFFFFF;
}
a:link {
color: #360051;
}
a:visited {
color: #360051;
}
a:hover {
color: #360051;
}
a:active {
color: #360051;
}
.style2 {color: #000000; font-size: 16px; }
-->
</style>
</head>
<body>
<div align="center">
<?php
echo '
<table summary="List of demo fields">
<tr>
<th><a href="?">Date[/url]</th>
<th><a href="?network">Network[/url]</th>
<th><a href="?userID">UserID[/url]</th>
<th><a href="?sale">Sale[/url]</th>
<th><a href="?saleID">SaleID[/url]</th>
<th><a href="?content">Content[/url]</th>
<th><a href="?site">Site[/url]</th>
</tr>';
$fp = fopen('logs.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
while (!feof($fp)) {
$line = fgets($fp,1024); //use 2048 if very long lines
$row++;
list ($date, $network, $userID, $sale, $saleID, $content, $site) = split ('\|', $line);
if ($sortby == 'date') $sortkey = strtotime($Date);
if ($sortby == 'network') $sortkey = strtolower($Network);
if ($sortby == 'userID') $sortkey = strtolower($UserID);
if ($sortby == 'sale') $sortkey = $Sale;
if ($sortby == 'saleID') $sortkey = strtolower($SaleID);
if ($sortby == 'content') $sortkey = strtolower($Content);
if ($sortby == 'site') $sortkey = $Site;
$col[$row] = array($sortkey, $date, $network, $userID, $sale, $saleID, $content, $site);
}
fclose($fp);
sort($col);
reset ($col);
$arrays = count($col) - 1;
$loop = -1;
while ($loop < $arrays) {
$loop++;
echo '
<tr>
<td>'.$col[$loop][1].'</td>
<td>'.$col[$loop][2].'</td>
<td>'.$col[$loop][3].'</td>
<td>'.$col[$loop][4].'</td>
<td>'.$col[$loop][5].'</td>
<td>'.$col[$loop][6].'</td>
<td>'.$col[$loop][7].'</td>
</tr>';
}
echo '
</table>
' ?>
</div>
</body>
</html>