表格数据没有显示分页PHP [英] Table Data is not showing with Pagination PHP

查看:67
本文介绍了表格数据没有显示分页PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续问题来自



问题2 :添加分页。代码示例取自此处
显示通知在这条线上的未定义指数。此外,想要下面的代码是安全的,并在表现的情况下好吗?


$ page = $ _ REQUEST ['p'];


以下是分页部分:

 <?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);

函数分页($ page,$ num_page)
{
echo'< ul style =list-style-type:none;>';
($ 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_pa​​ge.php?
P = $我。 '>'。$岛 '< / A>< /立GT;';
}
}
echo'< / ul>';
}
if($ num_page> 1)
{
分页($ page,$ num_page);
}


解决方案

  while($ stmt-> fetch()){

echo< tr>;
回显< td> 。 $ accountno。 < / TD> 中;
回显< td> 。 $ accountname。 < / TD> 中;
回显< td> 。 $ cname。 < / TD> 中;
回显< td> 。 $收入。 < / TD> 中;
回显< td> 。 $状态。 < / TD> 中;
回声< / tr>;
}

你是绑定的结果,但使用$ row来显示,它不会,所以试试



分页

  if(isset($ _ REQUEST [ p'])){
//然后所有分页代码
}


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);
       }

解决方案

while( $stmt->fetch()) {

        echo "<tr>";
        echo "<td>" . $accountno . "</td>";
        echo "<td>" . $accountname . "</td>";
        echo "<td>" . $cname . "</td>";
        echo "<td>" . $revenue . "</td>";
        echo "<td>" . $status . "</td>";
        echo "</tr>";
        }

you are binding result but using $row to display, it wont, so try this

for pagination

if(isset($_REQUEST['p'])){
//then all the code for pagination
}

这篇关于表格数据没有显示分页PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆