2015-02-08 134 views
-3

我有一些用於分頁數據的代碼。我的數據正在顯示,但分頁不起作用。我得到以下錯誤:警告:mysqli_free_result()期望只有1個參數,2給出

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

+0

錯誤/警告很明顯,不是嗎? – 2015-02-08 20:56:46

+1

@ Fred-ii-顯然,錯誤消息需要修復代碼才能幫助他。 – 2015-02-08 20:59:21

回答

2

編輯此行來檢查我的分頁代碼

$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); 
+0

很酷,錯誤不再顯示 但我的分頁,stil不顯示:'( – 2015-02-08 20:59:48

+0

mysqli_free_result()返回布爾值。那麼,你是否劃分一個布爾值?編輯..編輯解決方案 – sailesh 2015-02-08 21:03:12

+0

所以你可以給我一個解決方案? – 2015-02-08 21:09:13

0

MySQLi擴展沒有mysqli_result函數(它具有mysqli_result),而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()的返回值,並適當地處理錯誤。

相關問題