警告:mysqli_free_result() 需要 1 个参数,给定 2 个
Warning: mysqli_free_result() expects exactly 1 parameter, 2 given
我有一些数据分页代码。我的数据正在显示,但分页不起作用。我收到以下错误:
Warning: mysqli_free_result() expects exactly 1 parameter, 2 given
以前,我的分页使用 mysql,然后我将 mysql_result()
更改为 mysqli_free_result()
。
这是我的代码:
<table class="table table-striped table-hover fill-head">
<thead>
<tr>
<th>Code Poli</th>
<th>Name Poli</th>
<th>Floor</th>
<th style="width: 150px">Action</th>
</tr>
</thead>
<tbody>
<?php
$con=mysqli_connect("localhost","root","","klinik");
$per_page = 2;
$query = "SELECT COUNT(*) FROM poliknik";
$page_query = mysqli_query($con,$query);
$pages = ceil(mysqli_free_result($page_query, 0) / $per_page);
$page = (isset($_GET['hal'])) ? (int)$_GET['hal'] : 1;
$start = ($page - 1) * $per_page;
$data_kg=mysqli_query($con,"select * from poliknik order by id_poli DESC LIMIT $start,$per_page");
while ($kg=mysqli_fetch_object($data_kg)){
?>
<tr>
<td><?php echo $kg->kode?></td>
<td><?php echo $kg->name_poli?></td>
<td><?php echo $kg->lt?></td>
<td>
<a class="btn btn-primary btn-sm" href="home.php?p=edit_poliknik&id_poli=<?php echo $kg->id_poli ?>"><i class="fa fa-edit"></i> Edit</a>
<a class="btn btn-danger btn-sm" href="home.php?p=hapus_poliknik&id_poli=<?php echo $kg->id_poli ?>"><i class="fa fa-trash-o"></i> Delete</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<center>
<div>
<ul class="pagination pagination-lg pagination-colory">
<?php
if($pages >= 1 && $page <= $pages){
for($x=1; $x<=$pages; $x++){
echo ($x == $page) ? '<li class="active"><a href="home.php?p=poliknik&hal='.$x.'">'.$x.'</a></li>' : '<li><a href="home.php?p=poliknik&hal='.$x.'">'.$x.'</a></li>';
}
}
?>
</ul>
</div>
</center>
您可以使用 mysql > http://pastebin.com/CkyazRZM
查看我的分页代码
编辑这一行
$pages = ceil(mysqli_free_result($page_query, 0) / $per_page);
至
$pages = ceil(mysqli_fetch_array($page_query)[0] / $per_page);
mysqli_free_result($page_query);
MySQLi 扩展没有 mysqli_result
功能(它有一个 mysqli_result
class), and the mysqli_free_result
功能完全做其他事情。
您必须使用 mysqli_fetch_row()
或类似方法获取行并访问数据:
$query = "SELECT COUNT(*) FROM poliknik";
$page_query = mysqli_query($con,$query);
$r = mysqli_fetch_row ($page_query);
$count = $r[0];
$pages = ceil($count / $per_page);
不要忘记检查 mysqli_query()
和 mysqli_fetch_row()
的 return 值,并适当处理错误。
我有一些数据分页代码。我的数据正在显示,但分页不起作用。我收到以下错误:
Warning: mysqli_free_result() expects exactly 1 parameter, 2 given
以前,我的分页使用 mysql,然后我将 mysql_result()
更改为 mysqli_free_result()
。
这是我的代码:
<table class="table table-striped table-hover fill-head">
<thead>
<tr>
<th>Code Poli</th>
<th>Name Poli</th>
<th>Floor</th>
<th style="width: 150px">Action</th>
</tr>
</thead>
<tbody>
<?php
$con=mysqli_connect("localhost","root","","klinik");
$per_page = 2;
$query = "SELECT COUNT(*) FROM poliknik";
$page_query = mysqli_query($con,$query);
$pages = ceil(mysqli_free_result($page_query, 0) / $per_page);
$page = (isset($_GET['hal'])) ? (int)$_GET['hal'] : 1;
$start = ($page - 1) * $per_page;
$data_kg=mysqli_query($con,"select * from poliknik order by id_poli DESC LIMIT $start,$per_page");
while ($kg=mysqli_fetch_object($data_kg)){
?>
<tr>
<td><?php echo $kg->kode?></td>
<td><?php echo $kg->name_poli?></td>
<td><?php echo $kg->lt?></td>
<td>
<a class="btn btn-primary btn-sm" href="home.php?p=edit_poliknik&id_poli=<?php echo $kg->id_poli ?>"><i class="fa fa-edit"></i> Edit</a>
<a class="btn btn-danger btn-sm" href="home.php?p=hapus_poliknik&id_poli=<?php echo $kg->id_poli ?>"><i class="fa fa-trash-o"></i> Delete</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<center>
<div>
<ul class="pagination pagination-lg pagination-colory">
<?php
if($pages >= 1 && $page <= $pages){
for($x=1; $x<=$pages; $x++){
echo ($x == $page) ? '<li class="active"><a href="home.php?p=poliknik&hal='.$x.'">'.$x.'</a></li>' : '<li><a href="home.php?p=poliknik&hal='.$x.'">'.$x.'</a></li>';
}
}
?>
</ul>
</div>
</center>
您可以使用 mysql > http://pastebin.com/CkyazRZM
查看我的分页代码编辑这一行
$pages = ceil(mysqli_free_result($page_query, 0) / $per_page);
至
$pages = ceil(mysqli_fetch_array($page_query)[0] / $per_page);
mysqli_free_result($page_query);
MySQLi 扩展没有 mysqli_result
功能(它有一个 mysqli_result
class), and the mysqli_free_result
功能完全做其他事情。
您必须使用 mysqli_fetch_row()
或类似方法获取行并访问数据:
$query = "SELECT COUNT(*) FROM poliknik";
$page_query = mysqli_query($con,$query);
$r = mysqli_fetch_row ($page_query);
$count = $r[0];
$pages = ceil($count / $per_page);
不要忘记检查 mysqli_query()
和 mysqli_fetch_row()
的 return 值,并适当处理错误。