2017-11-10 6 views
0

私はPHPです。私はPHPのページネーションを使ってmysqlからレコードを表示する必要があります。私のコードでは、レコードは適切にフェッチされていますが、ページ番号が表示されています。事前にPHPでのページ設定が機能しない

display.php

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
<html> 

<body> 
<?php 
    $conn = new mysqli("localhost:3306", "root", "", "task"); 

    if ($conn->connect_error) { 
     die("Connection failed: " . $conn->connect_error); 
    } 
    $per_page= 30; 
    $sql="SELECT * FROM data"; 
    $result= $conn->query($sql); 


    if(isset($_GET['page']) && is_numeric($_GET['page'])){ 
     $page=$_GET['page']; 
    } 
    else{ 
     $page = 1; 
    } 
    $start =($page - 1) * $per_page; 
    $sql=$sql." LIMIT $start,$per_page"; 
    $query2 = $conn->query($sql); 
?> 
<table class="table table-bordered table-striped"> 
<thead> 
    <tr> 
    <th>Ticket ID</th> 
    <th>Tocken Number</th> 
    <th>Status</th> 
    </tr> 
<thead> 
<tbody> 
<?php 
while ($row = $result->fetch_assoc()) { 
?> 
      <tr> 
      <td><?php echo $row["ticket_id"]; ?></td> 
      <td><?php echo $row["tocken_no"]?></td> 
      <td><?php echo $row["status"] ?></td> 
      </tr> 
<?php 
}; 
?> 
</tbody> 
</table> 
<?php 
$row_cnt = $result->num_rows; 
    $pages = ceil($row_cnt/$per_page); 

$page_link="<div class='pagination'>"; 

for($i=1; $i<=$pages; $i++) 
{ 
$page_link .= "<a href='display.php?page=".$i."'>".$i."</a>"; 
} 
echo $page_link . "</div>"; 
?> 

</body> 
</html> 

感謝。

答えて

0

あなたは、これは動作するはず

<?php while ($row = $query2->fetch_assoc()) { ?> // $query2 you should pass the variable of limit query 

<?php while ($row = $result->fetch_assoc()) { ?> 

から、あなたのコードに変更するコードを単一の事を逃しました!

+0

私のコードは変更後に働いています。ありがとう –

+0

ようこそ! :) – KMS

関連する問題