PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 28th, 2012, 12:05 AM
wargamon wargamon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 25 wargamon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 51 m 17 sec
Reputation Power: 0
PHP-General - Pagination from XML using PHP

Hi, I need to create pages with data parsed from XML into PHP.

---catalog.xml---
<?xml version="1.0" encoding="ISO-8859-1"?>
<Catalog>
<Category>
<Name>CAT 1</Name>
<Location>
<Id>C01</Id>
<Description>This is CAT 1, ID C01</Description>
</Location>
<Location>
<Id>C02</Id>
<Description>This is CAT 1, ID C02</Description>
</Location>
<Location>
<Id>C03</Id>
<Description>This is CAT 1, ID C03</Description>
</Location>
<Location>
<Id>C04</Id>
<Description>This is CAT 1, ID C04</Description>
</Location>
</Category>
<Category>
<Name>CAT 2</Name>
<Location>
<Id>C05</Id>
<Description>This is CAT 2, ID C05</Description>
</Location>
<Location>
<Id>C06</Id>
<Description>This is CAT2, ID C06</Description>
</Location>
<Location>
<Id>C07</Id>
<Description>This is CAT 2, ID C07</Description>
</Location>
<Location>
<Id>C08</Id>
<Description>This is CAT2, ID C08</Description>
</Location>
<Location>
<Id>C09</Id>
<Description>This is CAT2, ID C09</Description>
</Location>
<Location>
<Id>C10</Id>
<Description>This is CAT2, ID C10</Description>
</Location>
</Category>
</Catalog>

---search.php---
[php]

$catalog = simplexml_load_file("catalog.xml");

foreach($catalog->Category[1]->Name as $name)
foreach($catalog->Category[1]->Location as $site)
foreach($site->Id as $ID)
foreach($site->Description as $desc)
{
$all_data[$i]["Name"] = $name;
$all_data[$i]["ID"] = $ID;
$all_data[$i]["Description"] = $desc;
$i++;
}

$limit = 3;
$page = (int) $_GET['page'];
$page = $page > 1 ? $page : 1;
$start = $limit * ($page - 1);

for($i=$start; $i<($start+$limit); $i++) {
$content.="
".'<table><tr><td>'.$all_data[$i]["Name"].'<br />'."
".'<br />'.$all_data[$i]["ID"].'<br />'."
".'<br />'.$all_data[$i]["Description"].'</td></tr></table>'."
";
}

echo $content;

$pages = ceil(count($all_data) / $limit);

$links = array();

for($i=1; $i<=$pages; $i++) {
$links[] = "<a href=\?page=".$i.">".$i."</a>";
}

echo implode(" - ",$links);


---Output---

CAT 2

C06

This is CAT2, ID C06
CAT 2

C07

This is CAT 2, ID C07
1 - 2


---Problem---
1. The result is not showing the first ID Node C05

2. The page link is not working. When click on 2, it just brings me to the server error without indicating the error code.

Can someone advise me how should I overcome this?

Reply With Quote
  #2  
Old November 28th, 2012, 01:42 AM
wargamon wargamon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 25 wargamon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 51 m 17 sec
Reputation Power: 0
Ok, I resolved the first problem due to the array. Now can someone tells me how to resolve the page link issue. Many thanks.

Reply With Quote
  #3  
Old December 28th, 2012, 09:26 PM
wargamon wargamon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 25 wargamon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 51 m 17 sec
Reputation Power: 0
Thanks all, I got this resolved.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Pagination from XML using PHP

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap