Markob1984 Posted December 10 Share Posted December 10 Im having a problem with my pagination code when i add a new record it isn't showing it and it shows the second last one again page 1 page 2 the top record is a duplicate of the 3rd one down of the image above and isnt showing the last record because of this can anyone help please below is the code <?php include('styles/top.php'); ?> <div id="left"> <?php if ($user_level !=1){ } else { include("css/menu.php"); ?> <?php } ?> </div> <div id="right"> <div id="view_box"> <ul> <li><img src="images/1.png" /></li> <!-- <li><img src="pics/2.jpg" /></li> --> <!-- <li><img src="pics/3.jpg" /></li> --> </ul> </div> <div id="button"> <ul> <!-- <li><button class="button" scroll_value="0">*</button></li> -- > <!-- <li><button class="button" scroll_value="600">*</button></li> --> <!-- <li><button class="button" scroll_value="1200">*</button></li> --> </ul> </div> <hr /> <?php if ($user_level !=1){ echo "No Access Allowed Admin Only "; } else { if(isset($_GET['page'])){ $page = $_GET['page']; } else { $page = 1; } if($page == '' || $page == 1){ $page1 = 0; } else { $page1 = ($page*4)-4; } $sql = "SELECT * FROM orders where orderby='Mark' ORDER By str_to_date(`paydate`, '%d/%m/%Y') ASC LIMIT ".$page1.", 4"; $data = $con->query($sql); ?> <h3>UPDATE / DELETE ORDERS</h3> <table border=1"> <tr> <th>CUSTOMER NAME </th> <th>PAY DATE</th> <th>AMOUNT</th> <th>STATUS</th> <th>UPDATE</th> <th>DELETE</th> </tr> <tr> <td> </td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <?php while ($myrow = mysqli_fetch_array($data)) { echo "<TR> <TD>".$myrow["customer_name"]."</TD> <TD>".$myrow["paydate"]."</TD> <TD>".$myrow["money"]."</TD> <TD>".$myrow["status"]."</TD>"; echo "<TD> <a href=\"update-edit-order.php?id=".$myrow['id']."\">UPDATE</a> </TD>"; echo "<TD> <a href=\"delete-order.php?id=".$myrow['id']."\">DELETE</a> </TD>"; echo "</TR>"; } ?> <tr> <td> </td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> <br /> <?php $sql = "SELECT * FROM orders where orderby='Mark'"; $data = $con->query($sql); $records = $data->num_rows; $records_pages = $records/4; $records_pages = ceil($records_pages); $prev = $page-1; $next = $page+1; echo '<ul class="paganation">'; if($prev >= 5){ echo '<li><a href="?page=1">First Page</a></li>'; } if($prev >=1){ echo '<li><a href="?page='.$prev.'">Previous</a></li>'; } if($records_pages >= 2 ){ for($r=1; $r <= $records_pages; $r++){ $active = $r == $page ? 'class="active"' : ''; echo '<li><a href="?page='.$r.'" '.$active.'>'.$r.'</a></li>'; } } if($next <= $records_pages && $records_pages >= 2){ echo '<li><a href="?page='.$next.'">Next</a></li>'; } if($page != $records_pages && $records_pages >= 5){ echo '<li><a href="?page='.$records_pages.'">Last Page</a></li>'; } echo '</ul>'; ?> <?php } ?> </div> <?php include('styles/bottom.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/326141-php-last-record/ Share on other sites More sharing options...
Markob1984 Posted December 10 Author Share Posted December 10 i have 38 records in the database but its showing 38 but 2 of them are duplicates and it isnt showing the newest record added until i add a new record? Quote Link to comment https://forums.phpfreaks.com/topic/326141-php-last-record/#findComment-1645333 Share on other sites More sharing options...
mac_gyver Posted December 10 Share Posted December 10 you are not seeing the new record until you add another one, because the overall code on your page is out of order. you are processing the post method form data after the point where you are querying for and displaying the data on the page. did you read my reply at the end of your previous thread? as to the data being repeated, when you examine the raw data in the database table are there duplicates? Quote Link to comment https://forums.phpfreaks.com/topic/326141-php-last-record/#findComment-1645341 Share on other sites More sharing options...
Mark2024 Posted December 10 Share Posted December 10 Hello there is no duplicates in the database Quote Link to comment https://forums.phpfreaks.com/topic/326141-php-last-record/#findComment-1645344 Share on other sites More sharing options...
Strider64 Posted December 11 Share Posted December 11 This might help as it comes from an old site that I did -> if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (isset($_GET['category'])) { $category = $_GET['category']; } else { error_log('Category is not set in the GET data'); $category = 'general'; } $total_count = $cms->countAllPage($category); } else { try { $category = 'general'; $total_count = $cms->countAllPage($category); } catch (Exception $e) { error_log('Error while counting all pages: ' . $e->getMessage()); } } /* * Using pagination in order to have a nice looking * website page. */ // Grab the current page the user is on if (isset($_GET['page']) && !empty($_GET['page'])) { $current_page = urldecode($_GET['page']); } else { $current_page = 1; } $per_page = 2; // Total number of records to be displayed: // Grab Total Pages $total_pages = $cms->total_pages($total_count, $per_page); /* Grab the offset (page) location from using the offset method */ /* $per_page * ($current_page - 1) */ $offset = $cms->offset($per_page, $current_page); // Figure out the Links that you want the display to look like $links = new Links($current_page, $per_page, $total_count, $category); // Finally grab the records that are actually going to be displayed on the page $records = $cms->page($per_page, $offset, 'cms', $category); and the retrieval -> $sql = 'SELECT * FROM '. $this->table . ' WHERE page =:page AND category =:category ORDER BY id DESC, date_added DESC LIMIT :perPage OFFSET :blogOffset'; $stmt = $this->pdo->prepare($sql); // Prepare the query: $stmt->execute(['page' => $page, 'perPage' => $perPage, 'category' => $category, 'blogOffset' => $offset]); // Execute the query with the supplied data: return $stmt->fetchAll(PDO::FETCH_ASSOC); It's kind of Sudo code, but I think you will get the drift. Quote Link to comment https://forums.phpfreaks.com/topic/326141-php-last-record/#findComment-1645389 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.