Click here to Skip to main content
15,917,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I make a PHP script but error :

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\NVCL\gallery_view.php on line 20

or

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\NVCL\gallery_view.php on line 24 Maaf, data dengan kriteria ini tidak ditemukan !

This is my code:

PHP
<?php
    session_start();
?>
<?php
    include("includes/query.php");
    function format_rupiah($angka){
        $rupiah=number_format($angka,0,',','.');
        return $rupiah;
    }
    $query = $_SESSION['query_gallery'];
?>
<?php
    $limit_data = 30;
    $halaman=$_GET["h"];
    if(empty($halaman)){
        $halaman=1;
    }
    $posisi = ($halaman-1)*$limit_data;
    $data_page = query($query); 
    $jumlah_data_page = mysqli_num_rows($data_page);            
    $jumlah_page = ceil($jumlah_data_page/$limit_data);                                 
    $query = $query." LIMIT $posisi, $limit_data";
    $data = query($query);
    if(mysqli_num_rows($data) == 0) {                            
        echo "
            <div style="font-size: 14px">
                Maaf, data dengan kriteria ini tidak ditemukan !
            </div>
        ";
    }
    else {
?>
<ul class="thumb">
<?php
    while($baris = mysqli_fetch_array($data)) {
        echo "
            <li><a href="movie_item.php?id=$baris[id_dvd]"></a></li>
        ";
    }
?>
</ul>
<div id="clear"></div>

<?php
    if(mysqli_num_rows($data) != 0 && $jumlah_page > 1) {
?>
<div style="padding-left: 11px; padding-bottom: 10px; padding-top: 0px">
<br>

<input type="button" value="Prev" onclick="showGallery(<?php $prev=$halaman-1; if($halaman>1)echo"$prev";else echo"1"; ?>)">
<?php
    $tot = 7;
    if($halaman % $tot == 0) $awal = ($halaman-$tot);
    else $awal = ($halaman - ($halaman % $tot));
    $akhir = $awal + $tot - 1;
    if($halaman>$tot){
        $page_string = "<input type='button' value='...' onclick=\"showGallery($awal-$tot+1)\"> ";  
    }else{
        $page_string = "";
    }

    for($i=($awal);$i<=($akhir);$i++){
        $btn=$i+1;
        if($i>($jumlah_page-1)) break;
        if($halaman==$btn){
            $disabled="disabled";
        }else{
                $disabled="";
        }
        if($btn==$jumlah_page) continue;
        $page_string.="<input type='button' value='$btn' onclick=\"showGallery($btn)\" $disabled> ";
    }
    if(($jumlah_page-$awal)>$tot){
        $page_string.="<input type='button' value='...' onclick=\"showGallery($awal+$tot+1)\"> ";
    }

    if($halaman==$jumlah_page) $last="disabled";
    else $last="";
    $page_string.="<input type='button' value='$jumlah_page' onclick=\"showGallery($jumlah_page)\" $last> ";

    echo"$page_string";
?>

        
        
        </div>
<?php
        }
    }
?>


What I have tried:

I tried to follow this code error Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in (directory) on line 20 and line 24 [duplicate]
Posted
Updated 20-Feb-17 17:58pm
v2

These line, the quote need to be escape (\") or change it to single quote

PHP
echo "
            <div style='font-size: 14px'>
                Maaf, data dengan kriteria ini tidak ditemukan !
            </div>
        ";


echo "
            <li><a href='movie_item.php?id=$baris[id_dvd]'></a></li>
        ";
 
Share this answer
 
v2
Comments
Member 13013510 21-Feb-17 0:09am    
I modified the code (") but still the same error
You should ascertain the result of
$query = $_SESSION['query_gallery'];
before passing it to mysqli_num_rows, check out the documentation[^].
 
Share this answer
 
Comments
Member 13013510 21-Feb-17 0:10am    
I'm still a beginner.. please explain the point. thanks
Peter Leow 21-Feb-17 0:51am    
below this line:
$query = $_SESSION['query_gallery'];
add this line to halt the script and see the value of $query:
die($query);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900