How does php read three xml data entries per page?

Source: Internet
Author: User
How does php read three xml data entries per page? The following code reads all the includesc fields of "9. xml": -------------------------------------------------------------------- how does php read three xml data entries per page?
The following code reads all the includesc fields of "9. xml:
-------------------------------------------
$ Xml_array = simplexml_load_file ('9. XML'); // read the data in xml to the array object.

Foreach ($ xml_array as $ tmp ){
Echo $ tmp-> includesc ."
";
}

?>
---------------------------------------------
Due to the large data volume, I want to display only three pieces of data per page. when I click "next", the next three pieces of data are displayed until all the data is displayed, the page does not change when you click "next. How can this problem be achieved? It is best to have code. thank you.

------ Solution --------------------
You output it like this.
Foreach ($ xml_array as $ tmp ){
Echo $ tmp-> includesc ."
";
}

This output is required.
$ Page = ($ _ GET ['Page']-1) * 3;
For ($ I = $ page; $ I <$ page + 3; $ I ++ ){
Echo $ xml [$ I]-> includesc ."
";
}

------ Solution --------------------
The boss's code is clear enough.
// Obtain the array
$ Xml_array = simplexml_load_file ('9. XML ');
// Start with the number of entries. If you do not require paging, there must be a data start position and offset.

// The starting position of the data is $ page. Suppose you want 2nd pages, then input the parameter $ _ GET ['Page'] = 2
// (2-1) * 3 is 3. The data is obtained by pressing the array key value, and the array key value starts from 0. So 0, 1, 2 is the first page, 3, 4, 5 is the second page
$ Page = ($ _ GET ['Page']-1) * 3;
// Cyclically 3 times. calculate the values of $ I, which are 3, 4, and 5 respectively. That is, the data with the key value 3, 4, and 5 described above
For ($ I = $ page; $ I <$ page + 3; $ I ++ ){
Echo $ xml [$ I]-> includesc ."
";
}
// The parameter passed in for the next page is $ _ GET ['Page'] + 1
------ Solution --------------------
That's your fault. you didn't provide the correct information from the very beginning.
Your
Foreach ($ xml_array as $ tmp ){
Echo $ tmp-> includesc ."
";
}
Cannot output document content
Only in this way can we
Foreach ($ xml_array-> news-> new as $ tmp ){
Echo $ tmp-> includesc ."
";
}

$ Xml_array-> news-> new is an array, so
$ Xml = $ xml_array-> news-> new;
$ Page = min (3, count ($ xml)-3 );
For ($ I = $ page; $ I <$ page + 3; $ I ++ ){
Echo $ xml [$ I]-> includesc ."
";
}
It was created.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.