Jump to content

Recommended Posts

Hi, i am new here and i am working on this script trying to fine tune it.

The problem is that i had this script for a while and thought it worked but it doesn't for the fully 100%.

It reads it's data from a CSV, than it shows certain entries from that CSV, that works, but when i use the page numbering script in it, it page numbers everything from the CSV file and not certain entries.

 

The part:    if ( $parts[5] == 9999) is the part where it loads a certain piece of the CSV, a certain row.

But it needs brackets, like this {

If i remove those brackets the page (next) and (previous) works, but when i put it the brackets in, the next and previous button continuously show the same 6 products over and over again.

How can i fix this ?

What i want that the results from the  if ( $parts[5] == 9999) is page numbered.

Here is my script:

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body bgcolor=#E2E965 link=#812990 vlink=#812990 alink=#812990 text=black>
</html>
<?PHP
$offset = isset($_GET['offset'])?$_GET['offset']:0;
$LinesToDisplay = 6;
$row = $offset + $LinesToDisplay + $parts[5];
$row2 = $offset - $LinesToDisplay;
$file_handle = fopen("web.txt", "rb");


while ((($parts = fgetcsv($file_handle,4096,"|")) !== FALSE)  && ($LinesToDisplay > 0) && 

(!feof($file_handle)))
{
    //new code
    //skip first $offset lines    
    if ($offset-- > 0)
    {
        continue;
    }

    ///////////////////////////
    
    $num = count($parts[1]);
   if ( $parts[5] == 9999)

$parts[0] = ucwords(strtolower($parts[0]));
$parts[1] = ucwords(strtolower($parts[1]));

echo "<p><a class='popup4' href='#'><font size=-1 

face=Humanist777BT-ExtraBlackB><b>$parts[0]</b></font>";
echo "<table><tr><td><i>";
echo "<span class='comment'>$parts[1]</span></td></tr></table></i></a>";
      echo  "<TABLE BORDER='0' cellpadding='0' CELLSPACING='0'><TR><TD WIDTH='70' 

HEIGHT='20' BACKGROUND='pricebackground.jpg' VALIGN='bottom'><center><font

color=white>€". $parts[2] ."</center></td></tr></table>";
echo "<b><font size=3 color=#D7182A>Op Voorraad In:<br></font>";
      echo (" Amsterdam ");
      if ( $parts[3] >= 1 )  echo ("<IMG SRC =green.gif>")."";
      if ( $parts[3] == 0 )  echo ("<IMG SRC =red.gif>")."";
      echo (" Utrecht ");
      if ( $parts[4] >= 1 )  echo ("<IMG SRC =green.gif>")."<div 

class='spacer_black'></div></b>";
      if ( $parts[4] == 0 )  echo ("<IMG SRC =red.gif>")."<div 

class='spacer_black'></div></b>";
     
      //new code
      //By here we decrement the line to display, when this reaches 0 the loop will stop
      $LinesToDisplay--;
      //////////////////////////////
}
fclose($file_handle);
?>
<html>
<BR><a href="occasion.php?offset=<?php echo $row2;?>">Previous</a> - <a 

href="occasion.php?offset=<?php echo $row;?>">Next</a></html>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/186379-some-csv-page-numbering-problems/
Share on other sites

I altered the script a little it seems to work but not the way i wanted.

It shows now, nothing, and if i press next a couple of 50 times, it will find the right entry eventually and than shows it.

So it only shows the items from the right colomn but only if you browse to all the columns first

 

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body bgcolor=#E2E965 link=#812990 vlink=#812990 alink=#812990 text=black>
</html>
<?PHP
$offset = isset($_GET['offset'])?$_GET['offset']:0;
$LinesToDisplay = 6;
$row = $offset + $LinesToDisplay;
$row2 = $offset - $LinesToDisplay;
$file_handle = fopen("web.txt", "rb");


while ((($parts = fgetcsv($file_handle,4096,"|")) !== FALSE)  && ($LinesToDisplay > 

0) && (!feof($file_handle)))
{
    //new code
    //skip first $offset lines    
    if ($offset-- > 0)
    {
        continue;
    }

    ///////////////////////////
       
$num = count($parts[5]);

   if ($parts[5] == 5400)
{

$parts[0] = ucwords(strtolower($parts[0]));
$parts[1] = ucwords(strtolower($parts[1]));

echo "<p><a class='popup4' href='#'><font size=-1 

face=Humanist777BT-ExtraBlackB><b>$parts[0]</b></font>";
echo "<table><tr><td><i>";
echo "<span class='comment'>$parts[1]</span></td></tr></table></i></a>";
      echo  "<TABLE BORDER='0' cellpadding='0' CELLSPACING='0'><TR><TD WIDTH='70' 

HEIGHT='20' BACKGROUND='pricebackground.jpg' VALIGN='bottom'><center><font

color=white>€". $parts[2] ."</center></td></tr></table>";
echo "<b><font size=3 color=#D7182A>Op Voorraad In:<br></font>";
      echo (" Amsterdam ");
      if ( $parts[3] >= 1 )  echo ("<IMG SRC =green.gif>")."";
      if ( $parts[3] == 0 )  echo ("<IMG SRC =red.gif>")."";
      echo (" Utrecht ");
      if ( $parts[4] >= 1 )  echo ("<IMG SRC =green.gif>")."<div 

class='spacer_black'></div></b>";
      if ( $parts[4] == 0 )  echo ("<IMG SRC =red.gif>")."<div 

class='spacer_black'></div></b>";



}
      //new code
      //By here we decrement the line to display, when this reaches 0 the loop will 

stop
      $LinesToDisplay--;
      //////////////////////////////
}
fclose($file_handle);
?>
<html>
<BR><a href="occasionb.php?offset=<?php echo $row2;?>">Previous</a> - <a 

href="occasionb.php?offset=<?php echo $row;?>">Next</a></html>

 

 

If you want to see it in action.

www.dwmusicstore.com/mark/occasionb.php

 

and if you press next 40 times, here is the first entry

http://www.dwmusicstore.com/mark/occasionb.php?offset=240

 

and here is the rest

http://www.dwmusicstore.com/mark/occasionb.php?offset=288

I did some adjustments to the script but not the result i want.

I am really getting headaches with this script.

I am now getting the right page with the right entries.

 

If i remove {continue;} from the script, and load it, than when i press NEXT, i get a blank page.

When i place it back and run it and press NEXT it just shows the same 6 entries instead of going to the next 6, why is this ?

what am i missing ?

 

Here is the script again, can someone please help me ?

 

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body bgcolor=#E2E965 link=#812990 vlink=#812990 alink=#812990 text=black>
</html>
<?PHP
$offset = isset($_GET['offset'])?$_GET['offset']:0;
$LinesToDisplay = 6;
$row = $offset + $LinesToDisplay;
$row2 = $offset - $LinesToDisplay;
$file_handle = fopen("web.txt", "rb");
error_reporting( E_ALL ); // DEBUGGING 

while ((($parts = fgetcsv($file_handle,4096,"|")) !== FALSE)  && ($LinesToDisplay > 0) && (!feof($file_handle)))
{
    //new code
    //skip first $offset lines    


$num = count($parts[5]);

if ($parts[5] == 5400)
{

if ($offset > 0)   
{continue;}

   

$parts[0] = ucwords(strtolower($parts[0]));
$parts[1] = ucwords(strtolower($parts[1]));

echo "<p><a class='popup4' href='#'><font size=-1 face=Humanist777BT-ExtraBlackB><b>$parts[0]</b></font>";
echo "<table><tr><td><i>";
echo "<span class='comment'>$parts[1]</span></td></tr></table></i></a>";
      echo  "<TABLE BORDER='0' cellpadding='0' CELLSPACING='0'><TR><TD WIDTH='70' HEIGHT='20' BACKGROUND='pricebackground.jpg' VALIGN='bottom'><center><font

color=white>€". $parts[2] ."</center></td></tr></table>";
echo "<b><font size=3 color=#D7182A>Op Voorraad In:<br></font>";
      echo (" Amsterdam ");
      if ( $parts[3] >= 1 )  echo ("<IMG SRC =green.gif>")."";
      if ( $parts[3] == 0 )  echo ("<IMG SRC =red.gif>")."";
      echo (" Utrecht ");
      if ( $parts[4] >= 1 )  echo ("<IMG SRC =green.gif>")."<div class='spacer_black'></div></b>";
      if ( $parts[4] == 0 )  echo ("<IMG SRC =red.gif>")."<div class='spacer_black'></div></b>";


      $LinesToDisplay--;
     }}
fclose($file_handle);
?>

<html>
<BR><a href="occasionb.php?offset=<?php echo $row2;?>">Previous</a> - <a href="occasionb.php?offset=<?php echo $row;?>">Next</a></html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.