hello everyone
has anyone done any pagination with PHP using an XML file for the data?
what i have is a PHP page that reads an XML file that contains product inventory and what i would like to do with that is break it up so it only displays 10 items per page as there are hundreds and the page gets really long.
i have done pagination with items pulled from a database but i have no idea where to start with the XML file.
any help would be great.
thanks
XML pagination with PHP
Moderator: General Moderators
-
QbertsBrother
- Forum Commoner
- Posts: 58
- Joined: Thu Oct 11, 2007 10:12 am
-
hitman6003
- Forum Newbie
- Posts: 4
- Joined: Mon Jun 23, 2008 7:36 pm
Re: XML pagination with PHP
Use a for loop that starts at the page number * the number per page:
Code: Select all
$start = $entries_per_page * $page_number;
for ($i = $start; $i < ( $start + $entries_per_page); $i++) {
print_r($array_of_xml[$i]);
}
-
QbertsBrother
- Forum Commoner
- Posts: 58
- Joined: Thu Oct 11, 2007 10:12 am
Re: XML pagination with PHP
thanks
i tried that and i am still getting all of the results that are in the XML file.
i am probably not doing it correctly. this outputs the all the records that are in the xml file.
i tried that and i am still getting all of the results that are in the XML file.
i am probably not doing it correctly. this outputs the all the records that are in the xml file.
Code: Select all
$entries_per_page = '1';
if (isset($_GET['pagenum'])) {
$page_number = $_GET['pagenum'];
}
else {
$page_number = 1;
}
if (isset($_GET['inventorytype'])) {
$inventorytype = $_GET['inventorytype'];
}
else {
$inventorytype = 'New';
}
if ($inventorytype == 'New'){
$inventoryFile = "inventory/newinventory.xml";
}
$start = $entries_per_page * $page_number;
$xml = @simplexml_load_file($inventoryFile) or die ("no file loaded");
$vehicleslist = $xml->listName;
foreach ($xml->vehicle as $vehicle) {
//echo "<h1>List: " . $vehicleslist . "</h1>";
for ($i = $start; $i < ( $start + $entries_per_page); $i++) {
//foreach ($vehicle->vin as $vehiclevin) {
print_r($vehicle[$i]);
//echo "<div class=\"vehiclerow\">
//<div class=\"vehicleimage\"><img src=\"images/vehicles/" . $vehicle->image01 ."\" /></div>
//<div class=\"vehicledesc\">Year: " . $vehicle->year . "<br />Make: " . $vehicle->make . "<br />Model: " . $vehicle->model . "</div>
//</div>";
}
//}
}
Re: XML pagination with PHP
Just wondering if you managed to solve this problem? I'm facing a similiar situation whereby I wish to split the XML data into multiple pages. Cheers.
Alex
Alex
-
QbertsBrother
- Forum Commoner
- Posts: 58
- Joined: Thu Oct 11, 2007 10:12 am
Re: XML pagination with PHP
i was able to get it to filter the results but when i would go to the next page it would show the same filtered results. i could not get it to show the next result set such as displaying the records 11 - 20. it would always show 1 - 10.
so i had to change how i am doing it and now i am loading the data into a database. i did not have the time to mass around with it now. maybe i will come back to it later.
i hope it works out for you.
so i had to change how i am doing it and now i am loading the data into a database. i did not have the time to mass around with it now. maybe i will come back to it later.
i hope it works out for you.