Continuation question from Here with pagination.
The basic code for displaying data in the table from mysql.
$stmt = $mysqli->prepare('SELECT accountno,accountname,cname,revenue,status FROM ***** WHERE user_id = ? ');
$stmt->bind_param('i', $user_id);
$stmt->bind_result($accountno ,$accountname, $cname, $revenue,$status);
$stmt->execute(); // Execute the prepared query.
echo "<table border='1'>
<tr>
<th>Account No</th>
<th>Account Name</th>
<th>Company Name</th>
<th>Revenue</th>
<th>Status</th>
</tr>";
while($row = $stmt->fetch()) {
echo "<tr>";
echo "<td>" . $row['accountno'] . "</td>";
echo "<td>" . $row['accountname'] . "</td>";
echo "<td>" . $row['cname'] . "</td>";
echo "<td>" . $row['revenue'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "</tr>";
}
$stmt->close();
echo "</table>";
Problem 1: With this code, it failed to load data. Showing the table, Showing even the row field but no data.
Problem 2: Adding pagination. Code Example was taken from here Showing Notice of undefining index at this line. Also, want to is this code below is safe and okay in case of performance?
$page=$_REQUEST['p'];
Here is the part for pagination:
<?php
//------------
$page=$_REQUEST['p'];
$limit=10;
if($page=='')
{
$page=1;
$start=0;
}
else
{
$start=$limit*($page-1);
}
$total=$stmt->num_rows;
$num_page=ceil($total/$limit);
function pagination($page,$num_page)
{
echo'<ul style="list-style-type:none;">';
for($i=1;$i<=$num_page;$i++)
{
if($i==$page)
{
echo'<li style="float:left;padding:5px;">'.$i.'</li>';
}
else
{
echo'<li style="float:left;padding:5px;"><a href="protected_page.php?
p='.$i.'">'.$i.'</a></li>';
}
}
echo'</ul>';
}
if($num_page>1)
{
pagination($page,$num_page);
}