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>
감사합니다.
내 코드가 변경된 후 작동 중입니다. 감사합니다. –
환영합니다 ....! :) – KMS