TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-09-2010, 07:28 PM   #21 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,324
Thanks: 5
Salathe is on a distinguished road
Default

Having been shown the source file being used, the problem is due to the line endings. The file uses Macintosh style line endings (\r only) rather than the more usual Unix (\n) or Windows (\r\n) endings. Because of this, PHP guessed (wrongly) that the entire file was only one super-long line.

Thankfully, you can instruct PHP to take a peek around the file and discover the true line ending character(s) for a file being read by setting the configuration option auto_detect_line_endings to 1 (it is 0, i.e. off, by default). In your script, before you try to read the file, just set that configuration option:

PHP Code:
ini_set('auto_detect_line_endings''1'); 
Well, that looks to be the problem anyway.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
davidapple (01-09-2010)
Old 01-09-2010, 09:10 PM   #22 (permalink)
The Wanderer
 
Join Date: Jan 2010
Posts: 22
Thanks: 2
davidapple is on a distinguished road
Default

Thanks,

This is amazing! Works a treat!

I'm really impressed that you managed to figure that out from my source file. I didn't realize that mac's TextEditor and PCs Notepad had different ways of creating new lines.

Now all I have to do is figure out how to number the pages and have next and previous page buttons, but I recon I can figure this out for myself. This is the easy part.

Keep up the good work.
davidapple is offline  
Reply With Quote
Old 01-09-2010, 09:41 PM   #23 (permalink)
The Wanderer
 
Join Date: Jan 2010
Posts: 22
Thanks: 2
davidapple is on a distinguished road
Default

Ah man! I wish I knew more about PHP. I'm struggling to implement the page hyperlinks

This is what I was trying out..
PHP Code:
$totalpages=ummm?

if (
$page 0){
echo 
'<a href="index.html?page=$page-1">Previous</a>'
}
if (
$page $totalpages){
echo 
'<a href="index.html?page=$page+1">Next</a>'
}
if (
$page umm?){
echo 
'<a href="index.html?page=$page+2">$page+2</a><a href="index.html?page=$page+3">$page+3</a><a href="index.html?page=$page+4">$page+4</a>'

It should be painfully obvious that I haven't really got a clue about PHP! I was hoping that goggling this could help but I couldn't find anything.
davidapple is offline  
Reply With Quote
Old 01-10-2010, 01:09 AM   #24 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Variable within single quotes will not be parsed, only double quotes.
__________________
My Blog
Enfernikus is offline  
Reply With Quote
The Following User Says Thank You to Enfernikus For This Useful Post:
davidapple (01-10-2010)
Old 01-10-2010, 02:07 AM   #25 (permalink)
The Wanderer
 
Join Date: Jan 2010
Posts: 22
Thanks: 2
davidapple is on a distinguished road
Default

I've figured most of it out now

The first thing to do is figure out what the current page is. You can't use $page because it returns 'Object ID 2'! Which is lame. So I did some maths with $offset and $perpage

PHP Code:
$currentpage = ($offset $perpage) / $perpage;

$nextpage = ($currentpage 1);
$previouspage = ($currentpage 1);

if (
$previouspage 0){
echo 
'<a href="test303.html?page='$previouspage .'">Previous Page</a> | <a href="test303.html?page='$previouspage .'">'$previouspage .'</a> | ';
}
echo 
''$currentpage .' | <a href="test303.html?page='$nextpage .'">'$nextpage .'</a> | <a href="test303.html?page='$nextpage .'">Next Page</a>'
Is this the most efficient way of doing this?

This returns the hyperlinks like this (for page 4)..
Previous Page | 3 | 4 | 5 | Next Page

And it doesn't let you go further back than page 1 (for page 1)..
1 | 2 | Next Page

I would like to include some more pages like this (for page 6)..
Previous Page | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Next Page

And I would also like to know if there is a way to prevent the Next Page hyperlink showing when you're on the last page. At the moment it just hangs!
davidapple is offline  
Reply With Quote
Old 01-10-2010, 09:21 AM   #26 (permalink)
The Wanderer
Newcomer 
 
Parvus's Avatar
 
Join Date: Aug 2008
Posts: 21
Thanks: 1
Parvus is on a distinguished road
Default

Quote:
And I would also like to know if there is a way to prevent the Next Page hyperlink showing when you're on the last page. At the moment it just hangs!
You could do a check on it, just like the previous page check on the first page.

PHP Code:
$maxpage count(file($file)); // Get the nr of lines in the file
if ($nextpage $maxpage){
echo 
'<a href="test303.html?page='$nextpage .'">'$nextpage .'</a> | <a href="test303.html?page='$nextpage .'">Next Page</a>';

Parvus is offline  
Reply With Quote
Old 01-10-2010, 11:24 AM   #27 (permalink)
The Wanderer
 
Join Date: Jan 2010
Posts: 22
Thanks: 2
davidapple is on a distinguished road
Default

Thanks Parvus. The count(file($lines)) bit is key.

I've integrated that in to the rest of my links script.

PHP Code:
$currentpage = ($offset $perpage) / $perpage;
$nextpage = ($currentpage 1);
$previouspage = ($currentpage 1);
$totalpages count(file($lines)) / $perpage;

if (
$previouspage 0){
echo 
'<a href="test303.html?page='$previouspage .'">Previous Page</a> | <a href="test303.html?page='$previouspage .'">'$previouspage .'</a>';
}

echo 
' | '$currentpage .' | ';

if (
$currentpage $totalpages){
echo 
'<a href="test303.html?page='$nextpage .'">'$nextpage .'</a> | <a href="test303.html?page='$nextpage .'">Next Page</a>';

Now I just have to add the extra page numbers so that people can skip 2 pags forward/back.
davidapple is offline  
Reply With Quote
Old 01-10-2010, 11:46 AM   #28 (permalink)
The Wanderer
 
Join Date: Jan 2010
Posts: 22
Thanks: 2
davidapple is on a distinguished road
Default

Yeah I've completely sorted this now. I've made it so you can actually skip 3 pages forwards or backwards.

PHP Code:
$currentpage = ($offset $perpage) / $perpage;
$nxtpage = ($currentpage 1);
$prevpage = ($currentpage 1);
$nxtnxtpage = ($currentpage 2);
$prevprevpage = ($currentpage 2);
$nxtnxtnxtpage = ($currentpage 3);
$prevprevprevpage = ($currentpage 3);
$totalpages count(file($lines)) / $perpage;

if (
$prevpage 0){
echo 
'<a href="test303.html?page='$prevpage .'">Previous Page</a>';}

if (
$prevpage 2){
echo 
' | <a href="test303.html?page='$prevprevprevpage .'">'$prevprevprevpage .'</a>';}

if (
$prevpage 1){
echo 
' | <a href="test303.html?page='$prevprevpage .'">'$prevprevpage .'</a>';}

if (
$prevpage 0){
echo 
' | <a href="test303.html?page='$prevpage .'">'$prevpage .'</a> | ';}

echo 
''$currentpage .'';

if (
$currentpage $totalpages){
echo 
' | <a href="test303.html?page='$nxtpage .'">'$nxtpage .'</a>';}

if (
$currentpage < ($totalpages 1)){
echo 
' | <a href="test303.html?page='$nxtnxtpage .'">'$nxtnxtpage .'</a>';}

if (
$currentpage < ($totalpages 2)){
echo 
' | <a href="test303.html?page='$nxtnxtnxtpage .'">'$nxtnxtnxtpage .'</a>';}

if (
$currentpage $totalpages){
echo 
' | <a href="test303.html?page='$nxtpage .'">Next Page</a>';} 
Is this the most efficient way of doing this or am I over complicating matters?
davidapple is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a sign-up feature to a flat file login script Peuplarchie General 2 10-23-2009 03:34 AM
Where is my file? superthin General 3 07-25-2009 10:48 AM
Flat file array, replace 3rd key value based on itself. Peuplarchie Absolute Beginners 1 07-22-2008 01:38 AM
Aptana Jaxer and file uploads xenon Advanced PHP Programming 2 06-06-2008 11:22 AM
Writing to XML file buildakicker General 8 02-06-2008 08:17 PM


All times are GMT. The time now is 07:11 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design