ivy
06-03-2005, 10:19 PM
I have a text file that contains:
Cadbury's|Boost|cadbury_boost|
Cadbury's|Bournville|cadbury_bournville|
Cadbury's|Chomp|cadbury_chomp|
Cadbury's|Crunchie|cadbury_crunchie|
Cadbury's|Curly Wurly|cadbury_curlywurly|
Cadbury's|Dairy Milk|cadbury_dairymilk|
.... and it goes on!
I would like to display the lines from the text file, but only 9 lines at a time, then add the prev-next links. I am using the following (a variant on some code i previously used from a tutorial):
<?php
// if a page isn't defined, we're on page one
if($page <= 0)
{
$page = 1;
}
// create an array of data
$file = file( 'products_text.txt' ) ;
$counter = "";
// how many lines of data to display
$display = 9;
// where to start depending on what page we're viewing
$start = ($page * $display) - $display;
// the actual news we're going to print
$news = array_slice($file, $start, $display);
// using the next bit of code, the various form entries can now be called upon
foreach($news as $line ){
list( $prodmanuf, $proddescr, $prodimage ) = explode('|', $line) ;
print("$prodmanuf, $proddescr, $prodimage<br>\n"); // this will be changed to a table layout
}
// printing the data
foreach($news as $key=>$value)
{
}
// The next bit is used for the next previous page coding
$newpage = $page + 1;
$prevpage = $page - 1;
$totalnews = count($file);
// This can be called to insert the previous and next links anywhere on the page
if($page > 1)
{
echo("<a href=\"http://www.website.com/thispage.php?page=$prevpage\">Previous listing </a> --");
}
else
{
}
if($totalnews > $page)
{
echo("-- <a href=\"http://www.website.com/thispage.php?page=$newpage\"> Next listing</a>");
}
else
{
}
?>
And it is not working properly!!!!
It displays 9 lines as I would like, but the next and previous do not function properly...... EVEN if I type ?page=3 after the URL, it still thinks it is on page 1!!! And the next link shows, links to ?page=2 but it displays page 1!!!
Very frustrating...
Any comments please woudl be most welcome!
Cadbury's|Boost|cadbury_boost|
Cadbury's|Bournville|cadbury_bournville|
Cadbury's|Chomp|cadbury_chomp|
Cadbury's|Crunchie|cadbury_crunchie|
Cadbury's|Curly Wurly|cadbury_curlywurly|
Cadbury's|Dairy Milk|cadbury_dairymilk|
.... and it goes on!
I would like to display the lines from the text file, but only 9 lines at a time, then add the prev-next links. I am using the following (a variant on some code i previously used from a tutorial):
<?php
// if a page isn't defined, we're on page one
if($page <= 0)
{
$page = 1;
}
// create an array of data
$file = file( 'products_text.txt' ) ;
$counter = "";
// how many lines of data to display
$display = 9;
// where to start depending on what page we're viewing
$start = ($page * $display) - $display;
// the actual news we're going to print
$news = array_slice($file, $start, $display);
// using the next bit of code, the various form entries can now be called upon
foreach($news as $line ){
list( $prodmanuf, $proddescr, $prodimage ) = explode('|', $line) ;
print("$prodmanuf, $proddescr, $prodimage<br>\n"); // this will be changed to a table layout
}
// printing the data
foreach($news as $key=>$value)
{
}
// The next bit is used for the next previous page coding
$newpage = $page + 1;
$prevpage = $page - 1;
$totalnews = count($file);
// This can be called to insert the previous and next links anywhere on the page
if($page > 1)
{
echo("<a href=\"http://www.website.com/thispage.php?page=$prevpage\">Previous listing </a> --");
}
else
{
}
if($totalnews > $page)
{
echo("-- <a href=\"http://www.website.com/thispage.php?page=$newpage\"> Next listing</a>");
}
else
{
}
?>
And it is not working properly!!!!
It displays 9 lines as I would like, but the next and previous do not function properly...... EVEN if I type ?page=3 after the URL, it still thinks it is on page 1!!! And the next link shows, links to ?page=2 but it displays page 1!!!
Very frustrating...
Any comments please woudl be most welcome!