I have fetched hundreds of records from XML to an array variable. When the array is echoed its output is:
array(1) {
[“photo”]=>
array(2) {
[”@attributes”]=>
array(3) {
[“baseURL”]=>
string(36) “http://www.myurl.com/photos/event_name11”
[“thumbDir”]=>
string(5) “thumb”
[“largeDir”]=>
string(6) “images”
}
[“pr”]=>
array(228) {
[0]=>
array(1) {
[”@attributes”]=>
array(5) {
[“w”]=>
string(3) “650”
[“h”]=>
string(3) “433”
[“p”]=>
string(10) “194393.JPG”
[“n”]=>
string(6) “194393”
[“d”]=>
string(0) “”
}
}
[1]=>
array(1) {
[”@attributes”]=>
array(5) {
[“w”]=>
string(3) “650”
[“h”]=>
string(3) “433”
[“p”]=>
string(10) “194394.JPG”
[“n”]=>
string(6) “194394”
[“d”]=>
string(0) “”
}
}
I want to display a total of 15 records in a single page, 5 in each row. Images' names and dimensions are in:
[“pr”]=>
array(228) {
I have tried using other PHP hard code but could not get desired result. It shows all the records in a single page.
How can I use pagination in CI?
What about:
$array = ...
$page = 0; // the page number you want to display
$entriesPerPage = 5;
for($i = 0; $i < $entriesPerPage; $i++)
{
$entry = $array['pr'][$page * $entriesPerPage + $i];
// output your $entry somehow
}
Or if you want to get 3 rows â 5 infos:
$array = ...
$page = 0; // the page number you want to display
$entriesPerRow = 5;
$rowsPerPage = 3;
for($i = 0; $i < $rowsPerPage; $i++)
{
for($j = 0; $j < $entriesPerRow; $j++)
{
$entry = $array['pr'][($page * $rowsPerPage + $i) * $entriesPerRow + $j];
// output your $entry somehow
}
// make a new line
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.