【解決方法】修正方法 ( ! ) 警告: mysqli_num_rows() は、パラメーター 1 が mysqli_result であると想定し、bool は D:\wamp64\www\livesearch\livesearch.php の 12 行目に指定されています

プログラミングQA


こんにちは、このエラーを修正するためにコードの助けが必要です mysqli_num_rows() は、パラメーター 1 が mysqli_result であることを想定しています。助けてください!

ajaxを使用したライブ検索でデータを表示するコードは次のとおりです

PHP
<pre>
<?php

include("config.php");
if(isset($_POST['input'])){

    $input = $_POST['input']; 

    $query = "SELECT * FROM wheat_genes WHERE Gene_Name LIKE '{$input}%' OR Gene_id LIKE '{$input}%' OR Gene_Annotation '{$input}%' OR Gene_Regulation LIKE '{$input}%'"; 

    $result = mysqli_query($con, $query); 
    
    if(mysqli_num_rows($result)>0){?>
        <table class="table table-bordered table-striped mt-4">
            <thead>
                 <tr>
                    <th>ID</th>
                    <th>Gene_id</th>
                    <th>Gene_Name</th>
                    <th>Gene_Annotation</th>
                    <th>Gene_Regulation</th>
                    <th>CDS</th>
                    <th>Primer_R</th>
                    <th>Primer_F</th>
                    <th>CG%</th>
                    <th>Compelet_seqence</th>
                 </tr>
            </thead>
            <tbody>
                <?php
                while($row=mysqli_fetch_assoc($result)){
                    $id = $row["ID"];
                    $Gene_id= $row["Gene_id"];
                    $Gene_Name = $row["Gene_Name"];
                    $Gene_Annotation = $row["Gene_Annotation"];
                    $Gene_Regulation = $row["Gene_Regulation"];
                    $CDS = $row["CDS"];
                    $Primer_R = $row["Primer_R"];
                    $Primer_F = $row["Primer_F"];
                    $CG = $row["CG%"];
                    $Compelet_seqence = $row["Compelet_seqence"];

                }
                ?>
                <tr>
                    <td><?php echo $ID ;?></td>
                    <td><?php echo $Gene_id ;?></td>
                    <td><?php echo $Gene_Name ;?></td>
                    <td><?php echo $Gene_Annotation ;?></td>
                    <td><?php echo $Gene_Regulation ;?></td>
                    <td><?php echo $CDS ;?></td>
                    <td><?php echo $Primer_R ;?></td>
                    <td><?php echo $Primer_F ;?></td>
                    <td><?php echo $CG ;?></td>
                    <td><?php echo $Compelet_seqence ;?></td>

                
                </tr>

            </tbody>
        </table>
        <?php
    

    }else{
        echo "<h4 class='text-danger text-center mt-3'>No data Found</h4>";
    }
    
};
?>    

私が試したこと:

PHP
<pre><?php

include("config.php");
if(isset($_POST['input'])){

    $input = $_POST['input']; 

    $query = "SELECT * FROM wheat_genes WHERE Gene_Name LIKE '{$input}%' OR Gene_id LIKE '{$input}%' OR Gene_Annotation '{$input}%' OR Gene_Regulation LIKE '{$input}%'"; 

    $result = mysqli_query($con, $query); 
    
    if(mysqli_num_rows($result)>0){?>
        <table class="table table-bordered table-striped mt-4">
            <thead>
                 <tr>
                    <th>ID</th>
                    <th>Gene_id</th>
                    <th>Gene_Name</th>
                    <th>Gene_Annotation</th>
                    <th>Gene_Regulation</th>
                    <th>CDS</th>
                    <th>Primer_R</th>
                    <th>Primer_F</th>
                    <th>CG%</th>
                    <th>Compelet_seqence</th>
                 </tr>
            </thead>
            <tbody>
                <?php
                while($row=mysqli_fetch_assoc($result)){
                    $id = $row["ID"];
                    $Gene_id= $row["Gene_id"];
                    $Gene_Name = $row["Gene_Name"];
                    $Gene_Annotation = $row["Gene_Annotation"];
                    $Gene_Regulation = $row["Gene_Regulation"];
                    $CDS = $row["CDS"];
                    $Primer_R = $row["Primer_R"];
                    $Primer_F = $row["Primer_F"];
                    $CG = $row["CG%"];
                    $Compelet_seqence = $row["Compelet_seqence"];

                }
                ?>
                <tr>
                    <td><?php echo $ID ;?></td>
                    <td><?php echo $Gene_id ;?></td>
                    <td><?php echo $Gene_Name ;?></td>
                    <td><?php echo $Gene_Annotation ;?></td>
                    <td><?php echo $Gene_Regulation ;?></td>
                    <td><?php echo $CDS ;?></td>
                    <td><?php echo $Primer_R ;?></td>
                    <td><?php echo $Primer_F ;?></td>
                    <td><?php echo $CG ;?></td>
                    <td><?php echo $Compelet_seqence ;?></td>

                
                </tr>

            </tbody>
        </table>
        <?php
    

    }else{
        echo "<h4 class='text-danger text-center mt-3'>No data Found</h4>";
    }
    
};
?>    

解決策 1

メッセージを見てください: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given.
パラメータ 1 とは何ですか? これは $result.
次に、PHPドキュメントを読んでください mysqli_query なぜそれが戻ってくるのかがわかります false、これはブール値であり、 mysqli_result.

コメント

タイトルとURLをコピーしました