Hướng dẫn mysqli_num_rows() expects parameter 1 to be mysqli_result string given - mysqli_num_rows() hy vọng tham số 1 là chuỗi mysqli_result đã cho

Tôi đang cố gắng tìm nạp dữ liệu theo truy vấn sau

$query= "SELECT * FROM residential "; 
            if($type!=""){
             $query.=" AND  type='$type'";
            }
            if($unit_type!=""){
             $query.=" AND  unit_type='$unit_type'";
            }
            if(($min_price!="") && ($max_price!="")){
             $query.=" AND  price BETWEEN '$min_price' AND '$max_price' ";
            }
            if(($min_bedrooms!="") && ($max_bedrooms!="")){
             $query.=" AND bedrooms BETWEEN '$min_bedrooms' AND '$max_bedrooms'";
            }
            if($query==FALSE){
                echo mysqli_error($connect);
                die;
            }
            $result= mysqli_query($connect,$query);

Đây là cách tôi sử dụng nó

<div class="row">
    <?php if(mysqli_num_rows($query)>0):?>
    <?php while($row=  mysqli_fetch_assoc($query)):
        print_r($row);
        die;
    ?>

    <div class="col-md-4 col-sm-4 col-xs-12">
        <div class="row property-listing">
            <div class="col-md-6 col-sm-6 col-xs-12">
               <img src="images/1.png" class="img-responsive full-width"> 
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12 property-desc">
                <h3>AED<br/>  <?php echo $row['price'];?></h3>
                <h5>Unit Type: <?php echo $row['unit_type'];?></h5>
                <h5>Available for :<?php echo $row['type'];?></h5>
                <h5>Location :<?php echo $row['area'];?></h5>
                <h5>Bedrooms :<?php echo $row['bedrooms'];?></h5>
            </div>
        </div>


    </div>

    <?php endwhile;?>
    <?php else:
        echo 'We found no record for your search criteria ';
        echo '<a href="index.html">Refine Search</a>'
        ?>

    <?php endif;?>

</div>

Đây là những gì tôi nhận được là lỗi

(!) Cảnh báo: mysqli_num_rows () mong đợi tham số 1 sẽ là mysqli_result

Các giá trị được đăng và tìm nạp là chính xác nhưng có điều gì đó không ổn với truy vấn, vui lòng giúp tôi sắp xếp nó

Cảm ơn

Khi được hỏi ngày 8 tháng 5 năm 2016 lúc 6:48May 8, 2016 at 6:48

Hướng dẫn mysqli_num_rows() expects parameter 1 to be mysqli_result string given - mysqli_num_rows() hy vọng tham số 1 là chuỗi mysqli_result đã cho

$query là chuỗi truy vấn của bạn không phải là bộ kết quả của bạn. Vì vậy, chỉ cần sử dụng

<div class="row">
    <?php if(mysqli_num_rows($query)>0):?>
    <?php while($row=  mysqli_fetch_assoc($query)):
        print_r($row);
        die;
    ?>

    <div class="col-md-4 col-sm-4 col-xs-12">
        <div class="row property-listing">
            <div class="col-md-6 col-sm-6 col-xs-12">
               <img src="images/1.png" class="img-responsive full-width"> 
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12 property-desc">
                <h3>AED<br/>  <?php echo $row['price'];?></h3>
                <h5>Unit Type: <?php echo $row['unit_type'];?></h5>
                <h5>Available for :<?php echo $row['type'];?></h5>
                <h5>Location :<?php echo $row['area'];?></h5>
                <h5>Bedrooms :<?php echo $row['bedrooms'];?></h5>
            </div>
        </div>


    </div>

    <?php endwhile;?>
    <?php else:
        echo 'We found no record for your search criteria ';
        echo '<a href="index.html">Refine Search</a>'
        ?>

    <?php endif;?>

</div>
0

<?php if(mysqli_num_rows($result)>0):?>
    <?php while($row=  mysqli_fetch_assoc($result)):

Đã trả lời ngày 8 tháng 5 năm 2016 lúc 7:00May 8, 2016 at 7:00

Hướng dẫn mysqli_num_rows() expects parameter 1 to be mysqli_result string given - mysqli_num_rows() hy vọng tham số 1 là chuỗi mysqli_result đã cho

George Pantgeorge PantGeorge Pant

2.0691 Huy hiệu vàng8 Huy hiệu bạc14 Huy hiệu đồng1 gold badge8 silver badges14 bronze badges

0

Chỉ cần thay đổi mã này

$query= "SELECT * FROM residential ";

Vào trong

$query= "SELECT * FROM residential WHERE 1"; 

Và thay đổi mã này

<?php if(mysqli_num_rows($query)>0):?>
    <?php while($row=  mysqli_fetch_assoc($query)):
        print_r($row);
        die;
    ?>

Đến

<?php 
$res = mysqli_query($con, $query); //replace $con with your db connection variable
if(mysqli_num_rows($res)>0):?>
    <?php while($row=  mysqli_fetch_assoc($res)):
        print_r($row);
        die;
    ?>

Đã trả lời ngày 8 tháng 5 năm 2016 lúc 6:51May 8, 2016 at 6:51

Hướng dẫn mysqli_num_rows() expects parameter 1 to be mysqli_result string given - mysqli_num_rows() hy vọng tham số 1 là chuỗi mysqli_result đã cho

0

Bạn đang thêm vào

<div class="row">
    <?php if(mysqli_num_rows($query)>0):?>
    <?php while($row=  mysqli_fetch_assoc($query)):
        print_r($row);
        die;
    ?>

    <div class="col-md-4 col-sm-4 col-xs-12">
        <div class="row property-listing">
            <div class="col-md-6 col-sm-6 col-xs-12">
               <img src="images/1.png" class="img-responsive full-width"> 
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12 property-desc">
                <h3>AED<br/>  <?php echo $row['price'];?></h3>
                <h5>Unit Type: <?php echo $row['unit_type'];?></h5>
                <h5>Available for :<?php echo $row['type'];?></h5>
                <h5>Location :<?php echo $row['area'];?></h5>
                <h5>Bedrooms :<?php echo $row['bedrooms'];?></h5>
            </div>
        </div>


    </div>

    <?php endwhile;?>
    <?php else:
        echo 'We found no record for your search criteria ';
        echo '<a href="index.html">Refine Search</a>'
        ?>

    <?php endif;?>

</div>
1 và
<div class="row">
    <?php if(mysqli_num_rows($query)>0):?>
    <?php while($row=  mysqli_fetch_assoc($query)):
        print_r($row);
        die;
    ?>

    <div class="col-md-4 col-sm-4 col-xs-12">
        <div class="row property-listing">
            <div class="col-md-6 col-sm-6 col-xs-12">
               <img src="images/1.png" class="img-responsive full-width"> 
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12 property-desc">
                <h3>AED<br/>  <?php echo $row['price'];?></h3>
                <h5>Unit Type: <?php echo $row['unit_type'];?></h5>
                <h5>Available for :<?php echo $row['type'];?></h5>
                <h5>Location :<?php echo $row['area'];?></h5>
                <h5>Bedrooms :<?php echo $row['bedrooms'];?></h5>
            </div>
        </div>


    </div>

    <?php endwhile;?>
    <?php else:
        echo 'We found no record for your search criteria ';
        echo '<a href="index.html">Refine Search</a>'
        ?>

    <?php endif;?>

</div>
2 Chuỗi truy vấn khi mong đợi
<div class="row">
    <?php if(mysqli_num_rows($query)>0):?>
    <?php while($row=  mysqli_fetch_assoc($query)):
        print_r($row);
        die;
    ?>

    <div class="col-md-4 col-sm-4 col-xs-12">
        <div class="row property-listing">
            <div class="col-md-6 col-sm-6 col-xs-12">
               <img src="images/1.png" class="img-responsive full-width"> 
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12 property-desc">
                <h3>AED<br/>  <?php echo $row['price'];?></h3>
                <h5>Unit Type: <?php echo $row['unit_type'];?></h5>
                <h5>Available for :<?php echo $row['type'];?></h5>
                <h5>Location :<?php echo $row['area'];?></h5>
                <h5>Bedrooms :<?php echo $row['bedrooms'];?></h5>
            </div>
        </div>


    </div>

    <?php endwhile;?>
    <?php else:
        echo 'We found no record for your search criteria ';
        echo '<a href="index.html">Refine Search</a>'
        ?>

    <?php endif;?>

</div>
3 - trong trường hợp của bạn là biến
<div class="row">
    <?php if(mysqli_num_rows($query)>0):?>
    <?php while($row=  mysqli_fetch_assoc($query)):
        print_r($row);
        die;
    ?>

    <div class="col-md-4 col-sm-4 col-xs-12">
        <div class="row property-listing">
            <div class="col-md-6 col-sm-6 col-xs-12">
               <img src="images/1.png" class="img-responsive full-width"> 
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12 property-desc">
                <h3>AED<br/>  <?php echo $row['price'];?></h3>
                <h5>Unit Type: <?php echo $row['unit_type'];?></h5>
                <h5>Available for :<?php echo $row['type'];?></h5>
                <h5>Location :<?php echo $row['area'];?></h5>
                <h5>Bedrooms :<?php echo $row['bedrooms'];?></h5>
            </div>
        </div>


    </div>

    <?php endwhile;?>
    <?php else:
        echo 'We found no record for your search criteria ';
        echo '<a href="index.html">Refine Search</a>'
        ?>

    <?php endif;?>

</div>
0.

Hướng dẫn mysqli_num_rows() expects parameter 1 to be mysqli_result string given - mysqli_num_rows() hy vọng tham số 1 là chuỗi mysqli_result đã cho

Hassaan

6.8985 Huy hiệu vàng29 Huy hiệu bạc49 Huy hiệu đồng5 gold badges29 silver badges49 bronze badges

Đã trả lời ngày 8 tháng 5 năm 2016 lúc 6:55May 8, 2016 at 6:55

Yair.RYair.RYair.R

7854 Huy hiệu bạc11 Huy hiệu đồng4 silver badges11 bronze badges

Trong truy vấn SQL của bạn, bạn không bao gồm mệnh đề WHERE.

Nếu bạn muốn kết hợp truy vấn của mình với đối số khác cho truy vấn SQL đầu tiên, hãy thêm một mệnh đề WHERE vào chuỗi SQL đầu tiên của bạnWHERE clause to your first sql string like this

<div class="row">
    <?php if(mysqli_num_rows($query)>0):?>
    <?php while($row=  mysqli_fetch_assoc($query)):
        print_r($row);
        die;
    ?>

    <div class="col-md-4 col-sm-4 col-xs-12">
        <div class="row property-listing">
            <div class="col-md-6 col-sm-6 col-xs-12">
               <img src="images/1.png" class="img-responsive full-width"> 
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12 property-desc">
                <h3>AED<br/>  <?php echo $row['price'];?></h3>
                <h5>Unit Type: <?php echo $row['unit_type'];?></h5>
                <h5>Available for :<?php echo $row['type'];?></h5>
                <h5>Location :<?php echo $row['area'];?></h5>
                <h5>Bedrooms :<?php echo $row['bedrooms'];?></h5>
            </div>
        </div>


    </div>

    <?php endwhile;?>
    <?php else:
        echo 'We found no record for your search criteria ';
        echo '<a href="index.html">Refine Search</a>'
        ?>

    <?php endif;?>

</div>
5 Ở đây TABLE_ID là khóa chính của bảng của bạn. Nó sẽ là một thực hành tốt để kết hợp truy vấn. Sau đó, bạn có thể thêm một giá trị khác để kết hợp truy vấn nhưtable_id is the primary key of your table.it will be a good practice for concatenating the query. after that you can add another values to concatenate the query like

if($type!=""){
   $query.=" AND  type='$type'";
}

Vì vậy, truy vấn cuối cùng của bạn một cái gì đó trông giống như

SELECT * FROM residential WHERE table_id!=0 AND type='$type'

Tiếp theo ở đây bạn đang chuyển $query cho mysqli_num_rows bạn nên vượt qua

<div class="row">
    <?php if(mysqli_num_rows($query)>0):?>
    <?php while($row=  mysqli_fetch_assoc($query)):
        print_r($row);
        die;
    ?>

    <div class="col-md-4 col-sm-4 col-xs-12">
        <div class="row property-listing">
            <div class="col-md-6 col-sm-6 col-xs-12">
               <img src="images/1.png" class="img-responsive full-width"> 
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12 property-desc">
                <h3>AED<br/>  <?php echo $row['price'];?></h3>
                <h5>Unit Type: <?php echo $row['unit_type'];?></h5>
                <h5>Available for :<?php echo $row['type'];?></h5>
                <h5>Location :<?php echo $row['area'];?></h5>
                <h5>Bedrooms :<?php echo $row['bedrooms'];?></h5>
            </div>
        </div>


    </div>

    <?php endwhile;?>
    <?php else:
        echo 'We found no record for your search criteria ';
        echo '<a href="index.html">Refine Search</a>'
        ?>

    <?php endif;?>

</div>
0 cho điều nàymysqli_num_rows you should pass the
<div class="row">
    <?php if(mysqli_num_rows($query)>0):?>
    <?php while($row=  mysqli_fetch_assoc($query)):
        print_r($row);
        die;
    ?>

    <div class="col-md-4 col-sm-4 col-xs-12">
        <div class="row property-listing">
            <div class="col-md-6 col-sm-6 col-xs-12">
               <img src="images/1.png" class="img-responsive full-width"> 
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12 property-desc">
                <h3>AED<br/>  <?php echo $row['price'];?></h3>
                <h5>Unit Type: <?php echo $row['unit_type'];?></h5>
                <h5>Available for :<?php echo $row['type'];?></h5>
                <h5>Location :<?php echo $row['area'];?></h5>
                <h5>Bedrooms :<?php echo $row['bedrooms'];?></h5>
            </div>
        </div>


    </div>

    <?php endwhile;?>
    <?php else:
        echo 'We found no record for your search criteria ';
        echo '<a href="index.html">Refine Search</a>'
        ?>

    <?php endif;?>

</div>
0 for this

Đã trả lời ngày 8 tháng 5 năm 2016 lúc 7:50May 8, 2016 at 7:50

Hướng dẫn mysqli_num_rows() expects parameter 1 to be mysqli_result string given - mysqli_num_rows() hy vọng tham số 1 là chuỗi mysqli_result đã cho

MujahidhmujahidhMujahidh

4103 Huy hiệu bạc17 Huy hiệu đồng3 silver badges17 bronze badges

Có bao nhiêu tham số được mong đợi trong hàm mysqli_num_rows ()?

mysqli_num_rows chỉ lấy một tham số a mysqli_result, vì vậy bạn cần xóa kết nối $ rf_koneksi khỏi cuộc gọi của bạn.one parameter a mysqli_result, so you need to remove the connection $rf_koneksi from your call.

Chức năng của mysqli_num_rows là gì?

Hàm mysqli_num_rows () trả về số lượng hàng trong một tập kết quả.returns the number of rows in a result set.

Loại trả lại của mysqli_query là gì?

Trả về các giá trị ¶ Đối với các truy vấn thành công tạo ra một tập kết quả, chẳng hạn như chọn, hiển thị, mô tả hoặc giải thích, mysqli_query () sẽ trả về đối tượng mysqli_result.Đối với các truy vấn thành công khác, mysqli_query () sẽ trả về đúng.mysqli_result object. For other successful queries, mysqli_query() will return true .