Web Design and Development Forums

[SOLVED] split xml search into multiple pages?

This is a discussion on "[SOLVED] split xml search into multiple pages?" within the PHP Forum section. This forum, and the thread "[SOLVED] split xml search into multiple pages? are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > PHP Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Apr 14th, 2008, 20:31   #1 (permalink)
Reputable Member
 
Join Date: Dec 2005
Location: scotland
Age: 26
Posts: 135
[SOLVED] split xml search into multiple pages?

I have a xml doc which i parse with simpleXML creating a bunch of results.

how would i go about splitting the results into different pages?
__________________
karloff is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 15th, 2008, 12:29   #2 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 520
Blog Entries: 4
Re: split xml search into multiple pages?

Something like this?

PHP: Select all

for($i=$page*10;$xml[$i]&&$i<($page+1)*10;$i++)
   echo 
$xml[$i]; 
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 15th, 2008, 21:09   #3 (permalink)
Reputable Member
 
Join Date: Dec 2005
Location: scotland
Age: 26
Posts: 135
Re: split xml search into multiple pages?

sorry, i'm a bit lost, could you explain further? how does that split my results up into different pages?
__________________
karloff is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 15th, 2008, 21:13   #4 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 520
Blog Entries: 4
Re: split xml search into multiple pages?

first, you get the entire array. Then let's say each page has 10 pages. So $i (the current item) is 10*(page_num-1). So on page 1 it starts at 0, page 2 it starts at 10, etc. Then we loop it until we A) run out of items, or B) Have displayed 10 products. That explain it any better?
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 15th, 2008, 22:16   #5 (permalink)
Reputable Member
 
Join Date: Dec 2005
Location: scotland
Age: 26
Posts: 135
Re: split xml search into multiple pages?

yup, i'll do some testing tomorrow and let you know

thanks
__________________
karloff is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 20:14   #6 (permalink)
Reputable Member
 
Join Date: Dec 2005
Location: scotland
Age: 26
Posts: 135
Re: split xml search into multiple pages?

cheers man, i have got so far but struggling to output all the results. it keeps looping the same result, can anyone see a prob?
PHP: 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++;
                  }
            
                
$properties = 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,
                  
'images'       => $images,
            
                
                
// setup image thumb
                //$image_thumb = substr($list->images->image[$count]->url, 0, -9);
              
);

            }        
//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($properties10);
          
// 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
            
foreach ($propertiesPages as $propertiesArray) {
              
// Show the information about the item
            
echo "<div class=\"property-box\"> ";
echo 
"<h3>price: " $properties['beds'] . " bedroom " .$properties['type'] ." based in " $properties['town'] ."</h3>";



            
// search and set the primary image counter for use
            //$count = 0;
            //while ($properties['image'][$count]->primary != 1) 
             // { 
              //$count++;
              //}
            // setup image thumb
//            $image_thumb = substr($properties['images'], 0, -9);

//            echo "<img src=\" " . $image_thumb . "med.jpg\" class=\"property-image\" alt=\"\" />" ;
            
echo "<h4>€" $properties['price'] . "</h4>";
            
// remove chars from description
            
$description substr($properties['description'], 0310);
            echo 
"<p> " nl2br($description) .   " ......</p>" ;
            echo 
"</div> ";        

 
//echo '<p><b>'.$properties['propertyid'].'</b> &nbsp; &pound;'.$properties['price'].'</p>';
            
}
            
// print out the page numbers beneath the results
            
echo $pageNumbers;
          }
        }
      
?>
??
__________________
karloff is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 20:43   #7 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 520
Blog Entries: 4
Re: split xml search into multiple pages?

This is your problem:

PHP: Select all

$properties = 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,
                  
'images'       => $images
It's just rewriting the $properties variable each time. You want something like this:

PHP: Select all

$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,
                  
'images'       => $images);

$cur_prop++; 
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 20:56   #8 (permalink)
Reputable Member
 
Join Date: Dec 2005
Location: scotland
Age: 26
Posts: 135
Re: split xml search into multiple pages?

i did try that but getting the a same results?
PHP: Select all

..................................................
$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,
                  
'images'       => $images,
            
                
                
// setup image thumb
                //$image_thumb = substr($list->images->image[$count]->url, 0, -9);
              
);
              
$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($properties10);
          
// 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
            
foreach ($propertiesPages as $propertiesArray) {
              
// Show the information about the item
            
$cur_prop 1;
            echo 
"<div class=\"property-box\"> ";
            echo 
"<h3>price: " $properties[$cur_prop]['beds'] . " bedroom " .$properties[$cur_prop]['type'] ." based in " $properties[$cur_prop]['town'] ."</h3>";



            
// search and set the primary image counter for use
            //$count = 0;
            //while ($properties['image'][$count]->primary != 1) 
             // { 
              //$count++;
              //}
            // setup image thumb
//            $image_thumb = substr($properties['images'], 0, -9);

//            echo "<img src=\" " . $image_thumb . "med.jpg\" class=\"property-image\" alt=\"\" />" ;
            
echo "<h4>€" $properties[$cur_prop]['price'] . "</h4>";
            
// remove chars from description
            
$description substr($properties[$cur_prop]['description'], 0310);
            echo 
"<p> " nl2br($description) .   " ......</p>" ;
            echo 
"</div> ";        
            
$cur_prop++;
              
//echo '<p><b>'.$properties['propertyid'].'</b> &nbsp; &pound;'.$properties['price'].'</p>';
            
}
            
// print out the page numbers beneath the results
            
echo $pageNumbers;
          }
        }
      
?> 
__________________
karloff is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 21:01   #9 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 520
Blog Entries: 4
Re: split xml search into multiple pages?

PHP: Select all

foreach ($propertiesPages as $propertiesArray) {
              
// Show the information about the item
            
$cur_prop 1
Put $cur_prop = 1; outside the foreach loop. It's setting it to one each pass, rendering the $cur_prop++; useless.
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 21:06   #10 (permalink)
Reputable Member
 
Join Date: Dec 2005
Location: scotland
Age: 26
Posts: 135
Re: split xml search into multiple pages?

ha ha, school boy error.

thanks, think i need to get my eye sight tested, didn't even see it
__________________
karloff is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 21:55   #11 (permalink)
Reputable Member
 
Join Date: Dec 2005
Location: scotland
Age: 26
Posts: 135
Re: split xml search into multiple pages?

doh!

now the pagination script only show the same results

would i need to use sessions? or should it output as normal? the example of pagination i followed did use sessions
__________________