Pagination Problems.

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
MrSomeone
Forum Newbie
Posts: 7
Joined: Sun Oct 10, 2004 8:36 am

Pagination Problems.

Post by MrSomeone »

Hey.

I have an image that logs every hit to a text file.
Each line in the text file looks like this:

Code: Select all

127.0.*.* time() Referer
Now, what I want to do is have the file output into pages with n amount of lines per page.
I thought I figured it out, however when I try to view the last few pages they are blank.

The working (not really) version can be viewed here: http://mrsomeone.com/s/l.php

And the code here: http://mrsomeone.com/s/l.phps

I've tryed multiple ways, and all of the tutorials I've seen are for PHP and MySQL, not a flat file DB.

I'm totally stumped, so any help would be greatly appreciated :wink:

-Someone
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

The only way I can see is by putting every line into an array.

Code: Select all

<?php

//num per page
$numpages = 25; 

$array = file_get_contents('file.txt');
$array  = explode("---whatever your seperator is---",$array);

if (empty($_GET['num']))
{

$_GET['num'] = 0;

}


?>

My ride just came so I have to go.. hope this gets you started... all you have to do is now simple math to calculate what to echo from the array, and then run a loop to echo them.

My advice, use a database.
MrSomeone
Forum Newbie
Posts: 7
Joined: Sun Oct 10, 2004 8:36 am

Post by MrSomeone »

The file is in an array, that's how I'm printing the results from the loop.

Code: Select all

$page['arr']          = file($file);
It's just that the pagination is messing up somewhere, just I can't seem to figure out where.
MrSomeone
Forum Newbie
Posts: 7
Joined: Sun Oct 10, 2004 8:36 am

Post by MrSomeone »

Anyone?

This is getting really annoying because I've gone over it multiple times.

(Don't just tell me to use a DB :P)
MrSomeone
Forum Newbie
Posts: 7
Joined: Sun Oct 10, 2004 8:36 am

Post by MrSomeone »

Okay... Decided to use MySQL instead.

final product.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

just a small question, how did you convert the last numbers into *s?
i've been trying to do that but haven't succeeded, could you share yuor code?

thanks
MrSomeone
Forum Newbie
Posts: 7
Joined: Sun Oct 10, 2004 8:36 am

Post by MrSomeone »

The way I did it is [php_man]explode()[/php_man] the IP Address by "." and then whether or not I am logged in as admin it either masks or doesn't mask the IP:

Code: Select all

<?php
 $ip = explode(".", $row['ip']);
 if ($_GET['password'] == "") // If admin
   $ip = $ip[0].".".$ip[1].".".$ip[2].".".$ip[3];    //Show full IP
 else
   $ip = $ip[0].".".$ip[1].".*.*";    // Show masked IP
?>
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

MrSomeone wrote:The way I did it is [php_man]explode()[/php_man] the IP Address by "." and then whether or not I am logged in as admin it either masks or doesn't mask the IP:

Code: Select all

<?php
 $ip = explode(".", $row['ip']);
 if ($_GET['password'] == "") // If admin
   $ip = $ip[0].".".$ip[1].".".$ip[2].".".$ip[3];    //Show full IP
 else
   $ip = $ip[0].".".$ip[1].".*.*";    // Show masked IP
?>
didn't think of that, thanks ;)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

And what happens if they have ipv6 address? ;)
There is no need to re-build the string because you have it already in $row['ip']

Code: Select all

if (...)
  $ip = $row['ip'];
Post Reply