Php 使用datatable时,表中的记录计数显示不正确
我正在根据查询返回的结果动态生成一个表,一切正常。表正在生成,datatable正在正确显示。但是记录的计数是错误的。这里的问题是,如果我得到10条记录,它将在计数中显示9条记录。但表中有10条记录。 请在这方面帮助我。 我的代码: PHP代码 表代码Php 使用datatable时,表中的记录计数显示不正确,php,mysql,sql,datatable,Php,Mysql,Sql,Datatable,我正在根据查询返回的结果动态生成一个表,一切正常。表正在生成,datatable正在正确显示。但是记录的计数是错误的。这里的问题是,如果我得到10条记录,它将在计数中显示9条记录。但表中有10条记录。 请在这方面帮助我。 我的代码: PHP代码 表代码 if (($getcolumns)||(mysql_errno == 0)) { echo "<table width='50%' class='table table-striped table-bordered table-
if (($getcolumns)||(mysql_errno == 0))
{
echo "<table width='50%' class='table table-striped table-bordered table-hover' align='center' 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>";
echo "<tbody>";
//display the data
while ($rows = mysql_fetch_assoc($getcolumns))
{
echo "<tr>";
foreach ($rows as $data)
{
echo "<td align='center' width=''>". $data . "</td>";
}
}
}else{
echo "<td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
}
echo "</tbody></table>";
}else{
echo "Error in running query :". mysql_error();
}
if(($getcolumns)| |(mysql_errno==0))
{
回声“
";
如果(mysql_num_rows($getcolumns)>0)
{
//循环遍历字段名称以打印正确的标题
$i=0;
而($i
我相信你的PHP代码,第四行是做问题,那就是
$row_getcolumns = mysql_fetch_assoc($getcolumns);
实际上,当您调用mysql\u fetch\u assoc时,它会从顶部获取记录,并将内部指针移动到下一条记录
因此,在创建表之前,您已经丢失了一条记录
这一行在您的代码中似乎是无用的。注释这一行并尝试。您能显示“$qry`$data=json\u decode(stripslashes($\u POST['data']),true)$qry=“选择
资产Id
,”$qry.=$数据$qry.=“来自已完成的交易”;只要做echo$qry
并查看查询,将此查询放入phpmyadmin中,然后检查得到的行数。也可以使用msqli
而不是mysql
。
$row_getcolumns = mysql_fetch_assoc($getcolumns);