且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PHP MySQL中基于搜索结果的总行数

更新时间:2023-02-05 23:37:37

在搜索了SO之后,我找到了以下答案:-

After Searching on SO, I found the answer below:-

if(isset($_POST['submit'])){
$a = $_POST['userInput'];  //user enter text for search

$query2 = "select sum(buy_price) as buyPrice, sum(sell_price) as sellPrice from mobile where mob_bill='$a' or mob_imei='$a' or mob_model='$a' or mob_status='$a'";
$result2 = mysqli_query($conn,$query2);
$output2="";
while($row2=mysqli_fetch_array($result2)){
        $buyPrice = $row2['buyPrice'];
        $sellPrice = $row2['sellPrice'];
}

$sql = "select * from mobile where mob_bill='$a' or mob_imei='$a' or mob_model='$a' or mob_status='$a'";
$result = mysqli_query($conn,$sql);
$output="";
while($row=mysqli_fetch_array($result)){
        $bill = $row['mob_bill'];
        $imei = $row['mob_imei'];
        $model = $row['mob_model'];

    $output.="<tr>
                <td>$bill</td>
                <td>$imei</td>
                <td>$model</td>
            </tr>"; 

 }
}
else{


}

<?php echo $outout; ?>
<?php echo $buyPrice; ?>
<?php echo $sellPrice; ?>