Jump to content

Recommended Posts

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

image.png.d0647406e6bddf93688bb891243486f5.png

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

image.png.38113b05a7d1608e82a3ee982b54af50.png

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>&nbsp;</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>&nbsp;</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'); ?>

 

Link to comment
https://forums.phpfreaks.com/topic/326141-php-last-record/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/326141-php-last-record/#findComment-1645341
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/326141-php-last-record/#findComment-1645389
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.