mercredi 11 septembre 2019

Sum Price Base on Value of Checkbox ID

I'd to ask a help from you guys, can you give me a hint or idean on how to execute this, I want to display the Total Price of checked values and display also the checked name below of the page for example is i check sika and suna it will sum the price and display them as checked values.. below is my simple code

  MY DATABASE VALUES:
+------+-----+------+
|ID    |Name |Price |
+------+-----+------+
|1     |amom |13    |
+------+-----+------+
|2     |sika |9     |
+------+-----+------+
|3     |suna |11    |
+------+-----+------+
|4     |data |15    |
+------+-----+------+
<?php
$connect=mysqli_connect("localhost","root","","test");

 $sql = "SELECT * FROM icheck ";
 $result = mysqli_query($connect, $sql);
 //$row = mysqli_fetch_array($result);
?>


<table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Price</th>
            <th>Check</th>
        </tr>
    </thead>
    <?php
    if(mysqli_num_rows($result)>0){
        $i=1;

    while($row=mysqli_fetch_array($result))
    {
echo'<tr>
    <td>'.$row['id'].'</td>
    <td>'.$row['name'].'</td>
    <td>'.$row['price'].'</td>
    <td><input type="checkbox" name="check" value='.$row['id'].'></td>

    ';
    $i++;
    }
    }
        ?>

</table>
<hr>
<p>You Select:</p>
<p>The Sum is</p>




Aucun commentaire:

Enregistrer un commentaire