php - display data 3 items in row with pagination 9 items on page from api or array -
i fetching data api. want display data 9 items on page , 3 items in row. have done it's screwing up. array data received api in $items
array.
$count_items=count($items); echo $count_items; $ptemp="http://".$_server['server_name'].$_server['request_uri']; $pt=explode('&',$ptemp); if (strpos($ptemp,'pageno')) array_pop($pt); $pt=implode('&',$pt); $ptemp=$pt; $array=$items; $page = $_request['pageno']; $currentpage = isset($page) ? (integer)$page : 1; echo 'currentpage='.$currentpage; $numperpage = 1; //number of rows displayed per page $total = ceil((count($array))/3); echo '$total='.$total; $numofpages = ceil($total / $numperpage); //total number of pages echo "numofpages=".$numofpages; if(isset($array)) { if (($currentpage > 0) && ($currentpages <= $numofpages)) { //starting loop array data $start = ($currentpage-1) * $numperpage; echo 'start='.$start; echo '<table border=1><th colspan=3><h3>data</h3></th><tr class="cbox" align="center">'; if($numperpage>=$total) {$numperpage=$total;} for($i=$start;$i<=($numperpage+$start-1);$i++) { echo 'currentpage='.$currentpage; echo 'i='.$i; $counter = 0; $rcount = 0; for($aa=$rcount;$aa<((ceil($count_items/3))*$currentpage);$aa++) { echo 'aa='.$aa; if ($counter++%3 == 0) { echo 'counter='.$counter; if ($counter > 0) { echo "</tr>"; } echo '<tr class="cbox">'; } //to display code , non-code parts of string table echo '<td>'; echo $items[$aa]['offerp1']; eval ($items[$aa]['offerp2']); if($_server['http_host']!="somedomain.com") { echo $items[$aa]['offerp3']; eval ($items[$aa]['offerp4']); } echo $items[$aa]['offerp5']; echo '</td>'; $rcount++; } if ($counter > 0) { echo "</tr>"; } } echo '<tr class="cbox"><td></td><td>some text</td><td><a href="file.php">more data</a></td></tr>'; echo "</table>"; } } if ($currentpage != 1) { //going page 1 should not bet allowed $previous_page = $currentpage - 1; $previous = '<a href="'.$ptemp.'?pageno='.$previous_page.'"> prev</a> '; } $pages = ''; ($a=1; $a<=$numofpages; $a++) { if ($a == $currentpage) $pages .= $a .'</u> '; else $pages .= '<a href="'.$ptemp.'?pageno='.$a.'" >'. $a .'</a> '; } $pages = substr($pages,0,-1); //removing last comma (,) if ($currentpage != $numofpages) { //going ahead of last page should not allowed $next_page = $currentpage + 1; //$next = ' <a href="'.$ptemp.'?pageno='.$next_page.'"> ></a>'; $next = ' <a href="'.$ptemp.'?pageno='.$next_page.'"> next</a>'; } $lastp=' <a href="'.$ptemp.'?pageno='.$numofpages.'"> last</a>'; echo ' '. $previous . $pages . $next . $lastp;
now problem same data displayed on pages. suppose if number of items 10 , testing 1 row per page 10 items showing on pages. please advice how can required number of rows per page.
edit: sorry results of code are: 4 items on page 1, 8 items on page 2, 10 items each on page 3 & 4. also, if there's simpler way welcome too.
Comments
Post a Comment