how to make php json decode pagination -
i looking php json pagination method/class. here code. how make each 2 json data group, pagination?
$body = file_get_contents("out_file.txt"); $json = json_decode($body,true); foreach($json $data){ echo $data['name'].' '; }
out_file.txt
[ {"name":"text1","num":"1"}, {"name":"text2","num":"2"}, {"name":"text3","num":"3"}, {"name":"text4","num":"4"}, {"name":"text5","num":"5"}, {"name":"text6","num":"6"} ]
i need divide data this:
page1
text1 text2
page2
text3 text4
page3
text5 text6
json data not "display" medium... it's data transfer format. how pageination of data within json body you, that's true of data structure, not json. given sample json structure array, you'd array indexing "page" offsets:
$page = 2; $items_per_page = 2; echo $json[$page * $items_per_page]['name'] // $json[4] -> text5 echo $json[$page * $items_per_page + 1]['name'] // $json[5] -> text6
Comments
Post a Comment