Hi guys,
I have a flat text database file with about 200 over records. How can i paginate them?
Appreciate if you can help me out, thanks.
Below is the script to get the records from the text file
PHP Code:
<?php // Open log file $logfile = "log.db";
if (file_exists($logfile)) {
$handle = fopen($logfile, "r"); $log = fread($handle, filesize($logfile)); fclose($handle); } else { die ("The log file doesn't exist!"); }
// Seperate each logline $log = explode("\n", trim($log)); // After that it may be useful to get each part of each logline in a separate variable. // This can be done by looping through each logline, and using explode again:
// Seperate each part in each logline for ($i = 0; $i < count($log); $i++) { $log[$i] = trim($log[$i]); $log[$i] = explode('|', $log[$i]); }
echo "<p>Total Entries : " . count($log) . "</p>";
// Show a table of the logfile echo '<style type="text/css"> body { background-color: #000; color: #ffff80; text-align: center; font-family: "Trebuchet MS", "Times New Roman", Arial, Times, serif; font-size: 13px }
.wrapper { width: 90%; text-align: center; margin: 0 auto; }
a { color: #33ccff; text-decoration: underline; }
a:hover { text-decoration: none; }
img { border: 0; }
.italic { font-style:italic; }
table { width: 100%; border-collapse: separate; text-align: center; margin: 0 auto; font-size: 13px }
td { background-color: #0f0f4f; padding: 3px; border: 1px ridge #ccc }
td.a { width: 12%; }
td.b { width: 32%; }
td.c { width: 56%; }
td.d { background-color: #000; }
</style>'; echo '<div class="wrapper"><table>'; foreach ($log as $logline) { if ($logline['1'] == '') { echo '<tr>'; echo '<td colspan="2"><b>' . $logline['2'] . '</b></td>'; echo '<td class="c"><span class="italic">' . htmlspecialchars(urldecode($logline['5'])) . '</span></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="a"><b>IP Address</b><br /><span class="italic">' . $logline['0'] . '</span></td>'; echo '<td class="b"><b>Hostname</b><br /><span class="italic">' . $logline['4'] . '</span></td>'; echo '<td class="c"><b>Browser/OS</b><br /><span class="italic">' . $logline['3'] . '</span></td>'; echo '</tr>'; echo '<tr><td class="d" colspan="3"></td></tr>'; } else { echo '<tr>'; echo '<td class="a"><a href="' . htmlspecialchars(urldecode($logline['1'])) . '"><b>Referer</b></a>'; echo '<td><b>' . $logline['2'] . '</b></td>'; echo '<td class="c"><span class="italic">' . htmlspecialchars(urldecode($logline['5'])) . '</span></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="a"><b>IP Address</b><br /><span class="italic">' . $logline['0'] . '</span></td>'; echo '<td class="b"><b>Hostname</b><br /><span class="italic">' . $logline['4'] . '</span></td>'; echo '<td class="c"><b>Browser/OS</b><br /><span class="italic">' . $logline['3'] . '</span></td>'; echo '</tr>'; echo '<tr><td class="d" colspan="3"></td></tr>'; } } echo '</table></div>'; ?>
|