Hey everyone, I am using simplexml to pull data from an external xml source. I have got values even for limiting the number of results to display. I thought I could paginate with a simple query within the URL, something like "&page=2" but it is not possible as far as documentation shows.
I downloaded a pagination class intended to use within a MYSQL query an tried to used the vars output from the xml. But the output is loading the whole results of the xml and not the specified within the URL vars.
I think what I might do is to count the results first and then paginate, which is what I am trying to do. Do you see anything in this code that can be improved? Sorry If it isn´t clear, but maybe discussing with some coders fellas I can see a bit of light at the end of the tunnel and exaplin a bit better.
So here is the code:
<?
$url ="http://www.somedomain.com/cgi/xml/engine/get_data.php?ref=$ref&checkin=$checkin&checkout=$checkout&rval=$rval&pval=$pval&country=$country&city=$city&lg=$lg&orderby=$orderby&ordertype=$ordertype&maxrows=$maxrows";
// see I am already defining the max num of rows within the url. Which means that the proper way to sort this out is to start counting from the # aheads?
$all = new SimpleXMLElement($url, null, true);
$all->items_total = $hotels->id;
//
require_once 'paginator.class.php';
//calling the paginator class
foreach($all as $hotel) // loop through our hotels
{
$pages = new Paginator;
//creating a new paginator $pages->mid_range = 7; $pages->items_total = $hotel->id; //extracting the var out from the XML
$rest = substr($hotel->description, 0, -150); // returns "abcde"
//echo <<<EOF
<table width="100%" border=0>
<tr>
<td colspan="2"><a href="{$hotel->rooms->room->bookUrl}">{$hotel->name}<span class="stars" widht="{$hotel->rating}">{$hotel->rating}</span></h2></a></a><p><b>Direccion:</b> <i>{$hotel->address}</i> - {$hotel->province}</p>
<td colspan="2"><div align="center">PRECIO: {$hotel->currencyCode} {$hotel->minCostOfStay</a>
</div></a></a>
</td>
</tr>
<tr>
<td colspan="2"> $rest...<a href="{$hotel->rooms->room->bookUrl}"><strong>ampliar información</strong></a></td>
<td valign="middle"><div align="center"><a href="{$hotel->rooms->room->bookUrl}"><img src="{$hotel->photoUrl}"></div></td>
</tr>
<tr>
<td colspan="2"><div align="center"><a href="{$hotel->rooms->room->bookUrl}"><strong>VER TODO SOBRE ESTE </strong></a></div></td>
<td colspan="2"><div align="center">$text</a></div></td>
</a></div></td>
</tr>
//EOF;
echo '</table>';
$pages->paginate();
}
echo $pages->display_pages();
?>