Page 1 of 1

pagination problem

Posted: Tue Apr 22, 2008 3:01 pm
by karloff
hi guys,

i have a xml doc which i'm parsing with php and trying to split into different pages. i can't seem to pass the results of the array further than page 1, all it show is m result for page 1 over an over but for the correct amont of results

the example i followed didn't use sessions and i haven't changed the pagintion.class.php

does anone know where i'm going wrong, mus be in the array somewhere

Code: Select all

<?php
 
        // Include the pagination class
        include 'pagination.class.php';
        // Create the pagination object
        $pagination = new pagination;
        
        // some example data
        // set xpath search
            $prop = $xml->xpath('/root/property[province="Alicante"]');
            // initiate the search and display list
            foreach ( $prop as $list) {
                  $propertyid   = $list->id ;
                  $date         = $list->date;
                  $ref          = $list->ref;
                  $price        = $list->price;
                  $pricefreq    = $list->price_freq;
                  $type         = $list->type->en;
                  $town         = $list->town;
                  $provinceName = $list->province;
                  $location     = $list->location_detail;
                  $beds         = $list->beds;
                  $baths        = $list->baths;
                  $pool         = $list->pool;
                  $description  = $list->desc->en->asXML();
                  $images       = $list->images->image;
                // search and set the primary image counter for use
                $count = 0;
                while ($list->images->image[$count]->primary != 1) 
                  { 
                  $count++;
                  }
                // setup image thumb
                $image = substr($list->images->image[$count]->url, 0, -9);
            
                $properties[$cur_prop] = array (
                  'propertyid'   => $propertyid,
                  'date'         => $date,
                  'ref'          => $ref,
                  'price'        => $price,
                  'pricefreq'    => $price_freq,
                  'type'         => $type,
                  'town'         => $town,
                  'provinceName' => $province,
                  'location'     => $location_detail,
                  'beds'         => $beds,
                  'baths'        => $baths,
                  'pool'         => $pool,
                  'description'  => $description,
                  'image'       => $image,
            
                
                
              );
              $cur_prop++;
            }        
//foreach ($properties as $key=> $value)
//{
//  echo $key."-".$value."";
//}
 
        // If we have an array with items
        if (count($properties)) {
          // Parse through the pagination class
          $propertiesPages = $pagination->generate($properties, 6);
          // If we have items 
          if (count($propertiesPages) != 0) {
            // Create the page numbers
            echo $pageNumbers = '<div class="numbers">'.$pagination->links().'</div>';
            // Loop through all the items in the array
            $current = 1;
            foreach ($propertiesPages as $propertiesArray) {
              // Show the information about the item
            
            echo "<div class=\"property-box\"> \n";
            echo "<h3>price: " . $properties[$current]['beds'] . " 
bedroom " .$properties[$current]['type'] ." based in " . $properties[$currrent]['town'] ."</h3>\n";
 
 
 
          
            $image_thumb = $properties[$current]['image'];
 
            echo "<img src=\" " . $image_thumb . "med.jpg\" class=\"property-image\" alt=\"\" />\n" ;
            echo "<h4>€" . $properties[$current]['price'] . "</h4>\n";
            // remove chars from description
            $description = substr($properties[$current]['description'], 0, 310);
            echo "<p> " . nl2br($description) .   " ......</p>\n" ;
            echo "</div> \n";        
            $current++;
              //echo '<p><b>'.$properties['propertyid'].'</b>   £'.$properties['price'].'</p>';
            }
            // print out the page numbers beneath the results
            echo $pageNumbers;
          }
        }
      ?>

Re: pagination problem

Posted: Wed Apr 23, 2008 1:25 pm
by karloff
can no-one help?

Re: pagination problem

Posted: Wed Apr 23, 2008 8:53 pm
by califdon
It's a bit hard to help without seeing the pagination class.

Re: pagination problem

Posted: Thu Apr 24, 2008 4:21 am
by karloff
oops, sorry. here is the code

Code: Select all

<?
 class pagination
  {
    var $page = 1; // Current Page
    var $perPage = 10; // Items on each page, defaulted to 10
    var $showFirstAndLast = false; // if you would like the first and last page options.
    
    function generate($array, $perPage = 10)
    {
      // Assign the items per page variable
      if (!empty($perPage))
        $this->perPage = $perPage;
      
      // Assign the page variable
      if (!empty($_GET['page'])) {
        $this->page = $_GET['page']; // using the get method
      } else {
        $this->page = 1; // if we don't have a page number then assume we are on the first page
      }
      
      // Take the length of the array
      $this->length = count($array);
      
      // Get the number of pages
      $this->pages = ceil($this->length / $this->perPage);
      
      // Calculate the starting point 
      $this->start  = ceil(($this->page - 1) * $this->perPage);
      
      // Return the part of the array we have requested
      return array_slice($array, $this->start, $this->perPage);
    }
    
    function links()
    {
      // Initiate the links array
      $plinks = array();
      $links = array();
      $slinks = array();
      
      // Concatenate the get variables to add to the page numbering string
      if (count($_GET)) {
        $queryURL = '';
        foreach ($_GET as $key => $value) {
          if ($key != 'page') {
            $queryURL .= '&'.$key.'='.$value;
          }
        }
      }
      
      // If we have more then one pages
      if (($this->pages) > 1)
      {
        // Assign the 'previous page' link into the array if we are not on the first page
        if ($this->page != 1) {
          if ($this->showFirstAndLast) {
            $plinks[] = ' <a  class="page_no" href="?page=1'.$queryURL.'">&laquo;&laquo; First </a> ';
          }
          $plinks[] = ' <a  class="page_no" href="?page='.($this->page - 1).$queryURL.'">&laquo; Prev</a> ';
        }
        
        // Assign all the page numbers & links to the array
        for ($j = 1; $j < ($this->pages + 1); $j++) {
          if ($this->page == $j) {
            $links[] = ' <a  class="page_no" class="selected">'.$j.'</a> '; // If we are on the same page as the current item
          } else {
            $links[] = ' <a class="page_no" href="?page='.$j.$queryURL.'">'.$j.'</a> '; // add the link to the array
          }
        }
  
        // Assign the 'next page' if we are not on the last page
        if ($this->page < $this->pages) {
          $slinks[] = ' <a  class="page_no" href="?page='.($this->page + 1).$queryURL.'"> Next &raquo; </a> ';
          if ($this->showFirstAndLast) {
            $slinks[] = ' <a class="page_no" href="?page='.($this->pages).$queryURL.'"> Last &raquo;&raquo; </a> ';
          }
        }
        
        // Push the array into a string using any some glue
        return implode(' ', $plinks).implode($this->implodeBy, $links).implode(' ', $slinks);
      }
      return;
    }
  }
?>