In PHP MySQL , I have made mobile shop system , in which user buy and sell the mobile and amount of buy & sell is inserted in database by form.
i am retrieve all the data from table in view and count total no of buy and sell price.
also i am seaching based on different parameters like mobile IMEI, Bill no, Model no,etc.
but after searching it will show results correctly, but i want to show the mobile price total according to their search.
if(isset($_POST['submit'])){
$a = $_POST['userInput']; //user enter text for search
$sql = "select * from mobile where mob_bill='$a' or mob_imei='$a' or mob_model='$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{
$sql = "select *, Sum(buy_payment) AS buyTotal, Sum(sell_payment) AS sellTotal from mobile";
$result = mysqli_query($conn,$sql);
$output1="";
while($row=mysqli_fetch_array($result)){
$bill = $row['mob_bill'];
$imei = $row['mob_imei'];
$model = $row['mob_model'];
$buy_payment=$row['buyTotal'];
$sell_payment=$row['sellTotal'];
$output1.="<tr>
<td>$bill</td>
<td>$imei</td>
<td>$model</td>
<td>$buy_payment</td>
<td>$sell_payment</td>
</tr>";
}
}
<?php echo $outout; ?>
<?php echo $outout1; ?>