分页不适用于jquery数据表

时间:2013-12-12 07:00:13

标签: php jquery datatable pagination paging

我正在使用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;?>"/>

请帮助我。

1 个答案:

答案 0 :(得分:0)

尝试以下修改后的代码,如果仍然不能正常工作,那么给实时URl显示你的html输出显示。

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