خرید بک لینک
since I changed my code to PDO statement and

from this:
PHP Code:

$get_total_rows $results->fetch_row(); 

this this:
PHP Code:

$get_total_rows $results->fetch(); 

My pagination shows correctly as 1 2 >

but when I click on Page 2, nothing happens?! please help?

Here is all my code:

PHP Code:

<?PHP
include('db.class.php'); // Database coection
$bdd = new db();
?>
<?php
require 'config1.php';
//echo 'fetch artwork loaded';

$db = new PDO('mysql:host=localhost;dbname=drupal;charset=utf8mb4''savingtinylives''***', array(PDO::ATTR_EMULATE_PREPARES => falsePDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$results $db->query('
  SELECT COUNT(*)
  FROM stl
  WHERE category = 1
'
);

//$get_total_rows = $results->fetchColumn();
//$get_total_rows = $results->fetch_row();
$get_total_rows $results->fetch();
$total_pages ceil($get_total_rows[0]/$item_per_page);

$itemArray = array();
$db->setAttribute(PDO::ATTR_EMULATE_PREPARESfalse);


$stmt $db->prepare('
    SELECT id, title, story, category, picurl, email, optin, storyshare, created
    FROM stl
    WHERE category = 1
    ORDER BY id ASC
        LIMIT :start, :count'
);
$stmt->execute([
    
':start' => $page_position,
    
':count' => $item_per_page
]);
$result $stmt->fetchAll(PDO::FETCH_ASSOC);
//continue only if $_POST is set and it is a Ajax request
if(isset($_POST) && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
echo 
'<div class="row">';
foreach (
$result as $row => $rs) {
    echo 
'<div class="col-md-2 col-sm-6 gallery-item">
                    <a href="#" class="gallery-link" data-toggle="modal" data-target="#map'
.$rs['id'].'"><img src="'.$rs['picurl'].'" width="100%" height="100%" /></a>';


                    echo 
'<div class="modal fade" id="map'.$rs['id'].'" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h2>Title: ' 
.$rs['title'].'</h2>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                                <div class="modal-body">
                                        <img src="'
.$rs['picurl'].'" width="100%" />
                                        <h5>' 
.$rs['name'].''s Story:</h5>
                                        <blockquote><span>“</span>'
.$rs['story'].'<span>”</span></blockquote>

                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>'
;
}
echo 
'</div>';
// you don't bind_result in PDO, just $stmt->fetch() and it will give you the row.

//echo $get_total_rows;
echo '<div align="center">';
    echo 
paginate_function($item_per_page$page_number$get_total_rows[0], $total_pages);
    echo 
'</div>';
exit;
}
    
################ pagination function #########################################
    
function paginate_function($item_per_page$current_page$total_records$total_pages)
    {
        
$pagination '';
        if(
$total_pages && $total_pages != && $current_page <= $total_pages){ //verify total pages and current page number
            
$pagination .= '<ul class="pagination">';

            
$right_links    $current_page 3;
            
$previous       $current_page 3//previous link
            
$next           $current_page 1//next link
            
$first_link     true//boolean var to decide our first link

            
if($current_page 1){
                
$previous_link = ($previous==0)? 1$previous;
                
$pagination .= '<li class="first"><a href="#" data-page="1" title="First">&laquo;</a></li>'//first link
                
$pagination .= '<li><a href="#" data-page="'.$previous_link.'" title="Previous">&lt;</a></li>'//previous link
                    
for($i = ($current_page-2); $i $current_page$i++){ //Create left-hand side links
                        
if($i 0){
                            
$pagination .= '<li><a href="#" data-page="'.$i.'" title="Page'.$i.'">'.$i.'</a></li>';
                        }
                    }
                
$first_link false//set first link to false
            
}

            if(
$first_link){ //if current active page is first link
                
$pagination .= '<li class="first active">'.$current_page.'</li>';
            }elseif(
$current_page == $total_pages){ //if it's the last active link
                
$pagination .= '<li class="last active">'.$current_page.'</li>';
            }else{ 
//regular current link
                
$pagination .= '<li class="active">'.$current_page.'</li>';
            }

            for(
$i $current_page+1$i $right_links $i++){ //create right-hand side links
                
if($i<=$total_pages){
                    
$pagination .= '<li><a href="#" data-page="'.$i.'" title="Page '.$i.'">'.$i.'</a></li>';
                }
            }
            if(
$current_page $total_pages){
                    
$next_link = ($i $total_pages) ? $total_pages $i;
                    
$pagination .= '<li><a href="#" data-page="'.$next_link.'" title="Next">&gt;</a></li>'//next link
                    
$pagination .= '<li class="last"><a href="#" data-page="'.$total_pages.'" title="Last">&raquo;</a></li>'//last link
            
}

            
$pagination .= '</ul>';
        }
        return 
$pagination//return pagination links
    
}
?>

I believe this may be a query / Ajax issue?!

here is my page:
Saving Tiny Lives

برچسب: نویسنده: آیلین رضوانی تاريخ: پنجشنبه 5 بهمن 1396 ساعت: 8:47

صفحه بندی