•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,987 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,781 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 587 | Replies: 4 | Solved
![]() |
Hi there guys & gals, this is my first post here will try to be as accurate as possible.
The problem i have seems to me to be quite basic but i cannot for the life of me work out how i can do it, am hoping you good folks can point me in the right direction.
I have data in .txt file format, single line per entry, passed into an array, single line to be displayed per page, what i cannot figure out is how to make a 'next page' and 'previous page' link to modify the var's i am using to correctly get the line in the file.
Here is my current php code active on the page it currently grabs var's from the address line
example: file.php?file_select=ttc01-10&chapter=8 where file_select = filename of the .txt file and chapter = the line to read and displayed.
Any advice, hints or tips would be greatly welcomed:
And what i would like is to get two links that update based on the var's to the previous line and the next line in the array.
Take care, and thanks for any replies
The problem i have seems to me to be quite basic but i cannot for the life of me work out how i can do it, am hoping you good folks can point me in the right direction.
I have data in .txt file format, single line per entry, passed into an array, single line to be displayed per page, what i cannot figure out is how to make a 'next page' and 'previous page' link to modify the var's i am using to correctly get the line in the file.
Here is my current php code active on the page it currently grabs var's from the address line
example: file.php?file_select=ttc01-10&chapter=8 where file_select = filename of the .txt file and chapter = the line to read and displayed.
Any advice, hints or tips would be greatly welcomed:
$file_select = 'ttc_intro'; if ($HTTP_GET_VARS) $file_select = $HTTP_GET_VARS['file_select']; if ($HTTP_POST_VARS) $file_select = $HTTP_POST_VARS['file_select']; $chapter = 0; if ($HTTP_GET_VARS) $chapter = $HTTP_GET_VARS['chapter']; if ($HTTP_POST_VARS) $chapter = $HTTP_POST_VARS['chapter']; $file_selected = $file_select.'.txt'; $lines = file($file_selected); $line = $lines[$chapter]; print '<br />'; print '<table width="685" align="center" cellspacing="1"><tr class="title_colour"><td colspan="2"><div align="center">'; print $line; print '</div></td></tr><tr class="title_colour"><td width="338"><div align="center"> <strong><< Previous Chapter </strong></div></td><td width="340"> <div align="center"><strong>Next Chapter >> </strong></div></td></tr></table>'; print '<br />';
And what i would like is to get two links that update based on the var's to the previous line and the next line in the array.
Take care, and thanks for any replies
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
php Syntax (Toggle Plain Text)
if($chapter!=0){ // if chapter has some value and if its not 0. $prev_link=$chapter - 1; //set previous link as chapter - 1. } else { $prev_link=0; //if chapter = 0, then theres no previous link, make it 0 as well. } if($chapter < count($lines)){ //if the chapter is less than the number of lines, next_link is valid. $next_link=$chapter + 1; //assign next chapter to $next_link } echo "<a href='file.php?chapter=$prev_link'>Previous chapter</a><br>"; echo "<a href='file.php?chapter=$next_link'>Next chapter</a><br>
[inline]
$file_select=(isset($_REQUEST['file_select']))?$_REQUEST['file_select']: "ttc_intro";[/inline] Here you are checking if file_select has been set by any of the methods, $_GET or $_POST. if its set, then assign that value to $file_select, else, assign ttc_intro to $file_select. You can do the same thing while checking for chapters as well..
Cheers,
Naveen
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Why thank you very much good sir 
I knew it wouldnt be too difficult to do but i am still a relative newbie to php, i think my php book might be a little out of date now. Thanks for the update on the GET and POST.
Going to implement your code soon, and hopefully that will have solved my problem, again thank you very much for your assistance.
-Daito

I knew it wouldnt be too difficult to do but i am still a relative newbie to php, i think my php book might be a little out of date now. Thanks for the update on the GET and POST.
Going to implement your code soon, and hopefully that will have solved my problem, again thank you very much for your assistance.
-Daito
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
After a bit of head scratching i worked out i needed to adapt the code a tiny wee bit to get it working but this is defiantly solved.
Where:
Now:
Again i thank you for taking the time to help me out
Where:
echo "<a href='file.php?chapter=$prev_link'>Previous chapter</a><br>"; echo "<a href='file.php?chapter=$next_link'>Next chapter</a><br>";
Now:
echo "<a href='file.php?file_select=$file_select&chapter=$prev_link'>Previous chapter</a><br>"; echo "<a href='file.php?file_select=$file_select&chapter=$next_link'>Next chapter</a><br>";
Again i thank you for taking the time to help me out
Last edited by DaitoTsu : Dec 6th, 2007 at 8:04 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- php/mysql dynamic multi-level menu problem (MySQL)
- Iframe opening new window problem (HTML and CSS)
- Using same swf for different links (Graphics and Multimedia)
- SATA HDD - problem after changing computer (Storage)
- mysql errors, from submit.php and index.php (PHP)
- Dynamic links in JSP page-need help (JSP)
- Dynamic Array, Writing to CSV, Floating Point ?'s (C)
- another newbie with alot of redhat and apache server Q'S (Linux Servers and Apache)
- Apache mod_rewrite with Google Ads (Linux Servers and Apache)
Other Threads in the PHP Forum
- Previous Thread: query in mysql
- Next Thread: Image not getting refreshed automatically



Linear Mode