Solution 1 :

tnx for everyone, i found this LINK
and that’s excatly what i was looking for.

    function getTotal(){
    var total = 0;
    $('.sum').each(function(){
        total += parseFloat(this.innerHTML)
    });
    $('#total').text(total);
}

getTotal();

$('.qty').keyup(function(){
    var parent = $(this).parents('tr');
    var price = $('.price', parent);
    var sum = $('.sum', parent);
    var value = parseInt(this.value) * parseFloat(price.get(0).innerHTML||0);
    sum.text(value);
    getTotal();
})

Solution 2 :

add $sum = 0; variable before while and put $sum += $row['price']; inside your while you can access $sum in Total Price <td>.
maybe you need int cast for $row['price'].

<table>
<tr>
    <td>Name</td>
    <td>Price</td>
    <td>Qty</td>
</tr>
<form action="sendorder.php?supid=<?php echo $supid; ?>" method="post">  
<?php
$sum = 0;
while($row = mysqli_fetch_array($result)) {
    $prodname = $row['name'];
    $supid = $row['supplier'];
    $prodid = $row['id'];
    $prodprice = $row['price'];
    $sum += $row['price'];
?>
<tr>
    <td>
        <input type="checkbox" name="prod[]" id="prod[<?php echo $prodid; ?>]" value="<?php echo $prodid; ?>">
            <label for="prod[<?php echo $prodid; ?>]"><?php echo $prodname; ?></label>
    </td>
    <td>
        <?php echo number_format($prodprice, 2); ?><label for="prod[<?php echo $prodid; ?>]"> NIS</label>
    </td>
    <td>
        <label for="prod[<?php echo $prodid; ?>]"><input style="font-size: 12px;" type="text" name="qty_<?php echo $prodid; ?>" placeholder="Qty" minlength="1" maxlength="3" size="2"></label>
    </td>
</tr>
<tr>
    <td><b>Total Price:</b></td>
    <td rowspan="1" colspan="2"><?php echo $sum; ?></td> \ HERE I WANT TO MAKE THE LIVE CALCLUTION
</tr>
<?php
}
?>
<tr>
    <td rowspan="1" colspan="3">
        <input type="submit" name="submit" value="Submit">
    </td>
</tr>
</form>

Problem :

I have a table of products (data pulled from SQL database) with this fields: ID, Name, Price.

After i pulled the data i have a QTY cell for each product…

I want to make a cell at the bottom to sum all the qty*prodcut price to get total price of the order…

That’s my table:

<table>
<tr>
    <td>Name</td>
    <td>Price</td>
    <td>Qty</td>
</tr>
<form action="sendorder.php?supid=<?php echo $supid; ?>" method="post">  
<?php
while($row = mysqli_fetch_array($result)) {
    $prodname = $row['name'];
    $supid = $row['supplier'];
    $prodid = $row['id'];
    $prodprice = $row['price'];
?>
<tr>
    <td>
        <input type="checkbox" name="prod[]" id="prod[<?php echo $prodid; ?>]" value="<?php echo $prodid; ?>">
            <label for="prod[<?php echo $prodid; ?>]"><?php echo $prodname; ?></label>
    </td>
    <td>
        <?php echo number_format($prodprice, 2); ?><label for="prod[<?php echo $prodid; ?>]"> NIS</label>
    </td>
    <td>
        <label for="prod[<?php echo $prodid; ?>]"><input style="font-size: 12px;" type="text" name="qty_<?php echo $prodid; ?>" placeholder="Qty" minlength="1" maxlength="3" size="2"></label>
    </td>
</tr>
<?php
}
?>
<tr>
    <td><b>Total Price:</b></td>
    <td rowspan="1" colspan="2">XXX NIS</td> \ HERE I WANT TO MAKE THE LIVE CALCLUTION
</tr>
<tr>
    <td rowspan="1" colspan="3">
        <input type="submit" name="submit" value="Submit">
    </td>
</tr>
</form>

Comments

Comment posted by Burham B. Soliman

@TangentiallyPerpendicular abusive replies does not make a sense, anyway he needs help with his current code, you could guide him to the right place to get his answer instead of that, i think we are here to help each other,

Comment posted by imvain2

I see your PHP/HTML, but I don’t see your attempt at solving the problem. You should try posting the javascript that you have tried to create but couldn’t get to work.

Comment posted by Tangentially Perpendicular

@BurhamB.Soliman This question is typical of so many questions here. The OP has posted something which he may or may not have produced himself, and asked a question that shows no effort whatsoever. It is a requirement of this site that askers have made an honest attempt to solve their problem before they ask. Without that requirement the site risks descending into a code-writing free-for-all that doesn’t mesh with the site’s objectives.

Comment posted by jquery selectors

you need to use jquery to call the result of the selected price and multiply it by the quantity .. so u could give it a try and do some search about jquery or javascript, and if you failed u can show up wt u tried and we would help you to solve it, here is a ref about

Comment posted by Saar Asor

Tangentially Perpendicular i dont want anyone to wrtie my code, i just want help… link to somewhere or some help… maybe i wasn’t clear but that’s only what i wanted… some help… any way iposted the solution for what i wanted, tnx!

Comment posted by imvain2

This doesn’t take into consideration the qty input that will be used AFTER the php is generated and sent to the browser.

By