Paginate Wallet Transactions
-
Hello @subratamal , i want to paginate the data fetched from the user transaction log api route. The default data just list out all the transactions, how can i paginate it please. i will share with you my current code below…
<?php $current_user = get_current_user_id(); $username = 'Admin'; $password = 'Password'; //Create the headers array. $headers = array( 'Content-Type: application/json', 'Authorization: Basic '. base64_encode("$username:$password") ); // Initiate API Transaction Route $trans = curl_init(); curl_setopt($trans, CURLOPT_URL, "https://pay.datoslink.com.ng/wp-json/wp/v2/wallet/$current_user"); curl_setopt($trans, CURLOPT_HTTPHEADER, $headers); curl_setopt($trans, CURLOPT_RETURNTRANSFER, true); curl_setopt($trans, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); curl_setopt($trans, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); curl_setopt($trans, CURLOPT_ENCODING, ''); $response = curl_exec($trans); if (curl_error($trans)) { die('Unable to connect: ' . curl_errno($trans) . ' - ' . curl_error($trans)); } curl_close($trans); // Decode API response $transDecode = json_decode($response, true); // use get variable to paging number $page = !isset($_GET['page']) ? 1 : $_GET['page']; $limit = 10; // five rows per page $offset = ($page - 1) * $limit; // offset $total_items = count($transDecode); // total items $total_pages = ceil($total_items / $limit); $final = array_splice($transDecode, $offset, $limit); // splice them according to offset and limit // Print Table $table .= <<<HTML <table style="width:100%;margin-bottom:.1em;table-layout: fixed;overflow:scroll;display: block;margin-top: -0.4em"> <tr class="trclass"> <th class="thclass">REF. ID</th> <th class="thclass">Date</th> <th class="thclass">TYPE</th> <th class="thclass">AMOUNT(?)</th> <th class="thclass">AVAIL. BALANCE(?)</th> <th class="thclass">DETAILS</th> </tr> HTML; foreach ($final as $transValue) { $table .= <<<HTML <tr> <td class="tdclass" style="width:auto;max-width:5%;vertical-align:middle"><strong>{$transValue['transaction_id']}</strong></td> <td class="tdclass" style="width:auto;max-width:20%;vertical-align:middle">{$transValue['date']}</td> <td class="tdclass" style="width:auto;max-width:13%;vertical-align:middle">{$transValue['type']}</td> <td class="tdclass" style="width:auto;max-width:16%;vertical-align:middle">{$transValue['amount']}</td> <td class="tdclass" style="width:auto;max-width:16%;vertical-align:middle">{$transValue['balance']}</td> <td class="tdclass" style="width:auto;max-width:30%;vertical-align:middle">{$transValue['details']}</td> </tr> HTML; } $table .= <<<HTML </table> HTML; echo $table; ?> <!-- print links --> <?php for($x = 1; $x <= $total_pages; $x++): ?> <a href='?page=<?php echo $x; ?>'><?php echo $x; ?></a> <?php endfor; ?>
Currently the pagination links is showing but the data are not changing when clicked on the links
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Paginate Wallet Transactions’ is closed to new replies.