【问题标题】:paging is not working for jquery datatable分页不适用于 jquery 数据表
【发布时间】:2013-12-30 11:32:08
【问题描述】:

我正在使用 jquery 表在网页上显示表。该表正常显示,但表分页和显示记录数和搜索选项不适用于生成的表。所有记录都填充在加载页面。这是我的代码 PHP 代码

$qry = " SELECT AssetId,";
$qry .= $data; 
$qry .= " from Completedetails";

mysql_select_db($database_finalkms, $finalkms);
$query_getcolumns = $qry;
$getcolumns = mysql_query($query_getcolumns, $finalkms) or die(mysql_error());
$row_getcolumns = mysql_fetch_assoc($getcolumns);
$totalRows_getcolumns = mysql_num_rows($getcolumns);

if (($getcolumns)||(mysql_errno == 0))  
{  
  echo "<table width='50%' id='sample_2'><thead><tr>";  
  if (mysql_num_rows($getcolumns)>0)  
  {  
          //loop thru the field names to print the correct headers  
          $i = 0;  
          while ($i < mysql_num_fields($getcolumns))  
          {  
       echo "<th align='center'>". mysql_field_name($getcolumns, $i) . "</th>";  
       $i++;  
    }  
    echo "</tr></thead>";  

    //display the data  
    while ($rows = mysql_fetch_array($getcolumns,MYSQL_ASSOC))  
    {  
      echo "<tbody><tr >";  
      foreach ($rows as $data)  
      {  
        echo "<td align='center'>". $data . "</td>";  
      }  
    }  
  }else{  
    echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";  
  }  
  echo "</tbody></table>";  
}else{  
  echo "Error in running query :". mysql_error();  
}  

?>

Java 脚本

<script>
 jQuery(document).ready(function() {       
  // initiate layout and plugins
  $("#sample_2").dataTable({"bPaginate": true});
 });
</script>

<input name="hdnfld" id="hdnfld" type="hidden" value="<?php echo $qry;?>"/>

请在这方面帮助我。

【问题讨论】:

    标签: php jquery datatable pagination paging


    【解决方案1】:

    尝试您的以下修改代码,如果仍然无法正常工作,请提供显示您的 html 输出的实时 URl。

    if (($getcolumns)||(mysql_errno == 0))  
    {
      // Displying the headers
      $i = 0;
      echo "<table width='50%' id='sample_2'><thead><tr>";
      while ($i < mysql_num_fields($getcolumns))  
      {  
        echo "<th align='center'>". mysql_field_name($getcolumns, $i) . "</th>";  
        $i++;  
      }  
      echo "</tr></thead>";  
    
      // Data Section
      echo "<tbody>";
      if (mysql_num_rows($getcolumns)>0)  
      {
        while ($rows = mysql_fetch_array($getcolumns, MYSQL_ASSOC))  
        {  
          echo "<tr>";
          foreach ($rows as $data)  
          {  
            echo "<td align='center'>". $data . "</td>";  
          }
          echo "</tr>";
        }  
      }else{  
        echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";  
      }  
      echo "</tbody></table>";  
    }else{  
      echo "Error in running query :". mysql_error();  
    }
    

    【讨论】:

    • 嗨 dipak,我已经根据表格结构更改了thead,但我仍然没有得到分页。请帮助我。
    • 嗨 depak 它正在工作这是因为 放置错误。非常感谢 dipak
    • 祝你好运。快乐编码:)
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签