Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
need help on flat file db pagination
Old 04-02-2009, 05:50 AM need help on flat file db pagination
Experienced Talker

Posts: 38
Trades: 0
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($handlefilesize($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>';
?>
superkingkong is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-02-2009, 10:39 AM Re: need help on flat file db pagination
Skilled Talker

Posts: 84
Trades: 0
One way is to put your entire records in to SESSION and after that display n number of records (say 20) also put another SESSION variable for page number. So for the first page you will be doing some thing like

$count = 20;

$start = $pageNum *$count +1;
$end = $pageNum *$count +20;

for ($i = $start; $i<$end; $i ++) {

// display your data

}

You have to set the $pageNum based on the Session variable for page number. So for the first page it will be 0;
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
- 1-888-869-HOST(4678)
Award winning Managed Hosting -
Please login or register to view this content. Registration is FREE

Managed Dedicated Servers. Reseller Discounts. 24/7 Impressive Tech Support
HivelocityDD is offline
Reply With Quote
View Public Profile
 
Old 04-02-2009, 06:56 PM Re: need help on flat file db pagination
Experienced Talker

Posts: 38
Trades: 0
hi,

thanks for the responce.
do i do something like this?

PHP Code:
<?php
session_start
();

$count 20;

$start $pageNum *$count +1;
$end $pageNum *$count +20;  


// Open log file
$logfile "log.db";

if (
file_exists($logfile)) {

$handle fopen($logfile"r");
$log fread($handlefilesize($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>';

for (
$i $start$i<$end$i ++) {

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>';
?>
please pardon me for my lack of knowledge in php.
superkingkong is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to need help on flat file db pagination
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12221 seconds with 12 queries