2016-05-03 8 views
0

Ich möchte eine Paginierung wie div machen. Im Moment ist div mit xml gefüllt, was 6 Ergebnisse anzeigt. Ich möchte mit einem Klick auf eine Schaltfläche die nächsten/vorherigen 6 Ergebnisse anzeigen. Ich habe keine Ahnung, wie man xml return Ergebnisse wie von Matches [0] zu Matches [5] und bei Next Click Matches [6] zu Matches [11] erzwingt.Anzeige xml Ergebnisse in Bereichen

XML in widget.php:

foreach ($xml->team->last_matches->match as $match) { 
    //some php and html stuff 
} 

, wenn Javascript Variable, die ich in Datei passieren widget.php limit ist, wollen etwas wie:

for ($x = 0; $x < $_GET['limit']; x++) 
    foreach ($xml->team->last_matches->match[x] as $match) { 
     //some php and html stuff 
    } 
} 

nicht sicher, wo zuletzt angeben, anzuzeigen sechs Einträge bis limit. Danke im Voraus.

Antwort

0

Verwenden Sie den xpath-Knotenindex, der durch eckige Klammern [] angegeben wird. Im Folgenden zeigt, mit einem Beispiel XML von Google Doodles:

XML

<root> 
    <GoogleDoodles> 
     <ID>1758</ID> 
     <DoodleDate>2015-07-01</DoodleDate> 
     <Doodle>Canada Day 2015</Doodle> 
    </GoogleDoodles> 
    <GoogleDoodles> 
     <ID>1759</ID> 
     <DoodleDate>2015-07-04</DoodleDate> 
     <Doodle>Fourth of July 2015</Doodle> 
    </GoogleDoodles> 
    <GoogleDoodles> 
     <ID>1760</ID> 
     <DoodleDate>2015-02-15</DoodleDate> 
     <Doodle>50th Anniversary of the Canadian Flag</Doodle> 
    </GoogleDoodles> 
    <GoogleDoodles> 
     <ID>1761</ID> 
     <DoodleDate>2015-02-15</DoodleDate> 
     <Doodle>Cricket World Cup 2015 - India vs. Pakistan</Doodle> 
    </GoogleDoodles> 
    <GoogleDoodles> 
     <ID>1762</ID> 
     <DoodleDate>2015-02-17</DoodleDate> 
     <Doodle>Carnival 2015</Doodle> 
    </GoogleDoodles> 
    <GoogleDoodles> 
     <ID>1763</ID> 
     <DoodleDate>2015-02-16</DoodleDate> 
     <Doodle>Rosenmontag 2015</Doodle> 
    </GoogleDoodles> 
    <GoogleDoodles> 
     <ID>1764</ID> 
     <DoodleDate>2015-02-18</DoodleDate> 
     <Doodle>Alessandro Volta's 270th Birthday</Doodle> 
    </GoogleDoodles> 
    <GoogleDoodles> 
     <ID>1765</ID> 
     <DoodleDate>2015-02-24</DoodleDate> 
     <Doodle>Rosalia de Castro's 178th Birthday</Doodle> 
    </GoogleDoodles> 
    <GoogleDoodles> 
     <ID>1766</ID> 
     <DoodleDate>2015-02-19</DoodleDate> 
     <Doodle>Lunar New Year 2015 (Vietnam)</Doodle> 
    </GoogleDoodles> 
    <GoogleDoodles> 
     <ID>1767</ID> 
     <DoodleDate>2015-02-26</DoodleDate> 
     <Doodle>Jose Mauro de Vasconcelos' 95th Birthday</Doodle> 
    </GoogleDoodles> 
    <GoogleDoodles> 
     <ID>1768</ID> 
     <DoodleDate>2015-02-19</DoodleDate> 
     <Doodle>Lunar New Year 2015</Doodle> 
    </GoogleDoodles> 
</root> 

PHP Script

$xml = simplexml_load_file('path/to/xml/file.xml'); 
# $xml = simplexml_load_string($xmlstring); 

$limit = 5; 

for($j=0; $j <= $limit; $j++) { 

    foreach ($xml->xpath("//GoogleDoodles[".$j."]/Doodle") as $d) { 
     echo $d->saveXML()."\n"; 
    } 

}  

// <Doodle>Canada Day 2015</Doodle> 
// <Doodle>Fourth of July 2015</Doodle> 
// <Doodle>50th Anniversary of the Canadian Flag</Doodle> 
// <Doodle>Cricket World Cup 2015 - India vs. Pakistan</Doodle> 
// <Doodle>Carnival 2015</Doodle> 
Verwandte Themen