i am learning php recently. i get the table from database but i face problem giving pagination to that table.
i don't know how to give pagination to the database table how can i do that.
This is my code
<?php
// If user not logged in then show login message
if (!isset($_SESSION['userid'])) {
?><div class="message">
To access this page, you must be logged.<br />
<a href="connexion.php">Log in</a>
</div><?php
}
else{
//Video count values of the database
if(isset($_REQUEST['date1']) && isset($_REQUEST['date2'])){
$dnn = mysqli_query($conn, 'select video_date,video_count from video_master where rec_id="'.$_SESSION['userid'].'" and video_date >= "' . $_REQUEST['date1'] . '" and video_date <= "' . $_REQUEST['date2'] . '"');
}
else{
$dnn = mysqli_query($conn, 'select video_date,video_count from video_master where rec_id="'.$_SESSION['userid'].'"');
}
if(mysqli_num_rows($dnn)>0)
{
?><table>
<thead>
<tr>
<th>Date</th>
<th>Video Count</th>
</tr></thead><?php
while($rowData = mysqli_fetch_array($dnn)){
//$video_date = date("Y-m-d","d-m-Y",$rowData['video_date']);
$video_date = $rowData['video_date'];
$video_count = $rowData['video_count'];
?><tbody><tr>
<td><?php print($video_date); ?></td>
<td><?php print($video_count); ?></td>
</tr></tbody><?php
}
?></table><?php
}
?>
<?php
}
?>
THE CODE WHICH I TRY BUT IN THIS CODE I GET ONLY NUMBERS UNDER MY TABLE THE VALUE IS NOT GET CHANGE ON CLICKING ON NUMBER.
<?php
$per_page=5;
if (isset($_GET["page"])) {
$page = $_GET["page"];
}
else {
$page=1;
}
// Page will start from 0 and Multiple by Per Page
$start_from = ($page-1) * $per_page;
//Selecting the data from table but with limit
$query = "SELECT * FROM video_master LIMIT $start_from, $per_page";
$result = mysqli_query ($conn, $query);
// If user not logged in then show login message
if (!isset($_SESSION['userid'])) {
?><div class="message">
To access this page, you must be logged.<br />
<a href="connexion.php">Log in</a>
</div><?php
}
else{
//Video count values of the database
if(isset($_REQUEST['date1']) && isset($_REQUEST['date2'])){
$dnn = mysqli_query($conn, 'select video_date,video_count from video_master where rec_id="'.$_SESSION['userid'].'" and video_date >= "' . $_REQUEST['date1'] . '" and video_date <= "' . $_REQUEST['date2'] . '"');
}
else{
$dnn = mysqli_query($conn, 'select video_date,video_count from video_master where rec_id="'.$_SESSION['userid'].'"');
}
if(mysqli_num_rows($dnn)>0)
{
?><table>
<thead>
<tr>
<th>Date</th>
<th>Video Count</th>
</tr></thead><?php
while($rowData = mysqli_fetch_array($dnn)){
//$video_date = date("Y-m-d","d-m-Y",$rowData['video_date']);
$video_date = $rowData['video_date'];
$video_count = $rowData['video_count'];
?><tbody><tr>
<td><?php print($video_date); ?></td>
<td><?php print($video_count); ?></td>
</tr></tbody><?php
}
?></table><?php
//Now select all from table
$query = "select * from video_master";
$result = mysqli_query($conn, $query);
// Count the total records
$total_records = mysqli_num_rows($result);
//Using ceil function to divide the total records on per page
$total_pages = ceil($total_records / $per_page);
//Going to first page
echo "<center><a href='reports.php?page=1'>".'First Page'."</a> ";
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='reports.php?page=".$i."''>".$i."</a>";
};
// Going to last page
echo "<a href='reports.php?page=$total_pages'>".'Last Page'."</a></center> ";
}
?>
<?php
}
?>