Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to list invoices from a database with the following PHP Code:

<table width="800" border="0" cellspacing="0" cellpadding="10">
<?php
$sql="SELECT * from billing_pdf_archive order by invoice_number ASC ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$counter=0;
while($result=mysql_fetch_array($rs))
{
    $counter++;
    $sql2="SELECT * from customer where sequence = '".$result["customer_sequence"]."' ";
    $rs2=mysql_query($sql2,$conn) or die(mysql_error());
    $result2=mysql_fetch_array($rs2);

    $sql3="SELECT * from reseller where sequence = '".$result["reseller_sequence"]."' ";
    $rs3=mysql_query($sql3,$conn) or die(mysql_error());
    $result3=mysql_fetch_array($rs3);

    if($result["customer_sequence"] != '0')
    {
        $company = $result2["company"];
    }
    elseif($result["reseller_sequence"] != '0')
    {
        $company = '<strong>Reseller: </strong>'.$result3["company"];
    }

    echo '<tr>
    <td width="5%"><input type="checkbox" name="check'.$counter.'" id="check'.$counter.'" value="checked" /></td>
    <td width="20%">'.$result["invoice_number"].'</td>
    <td width="35%">'.$company.'</td>
    <td width="20%">'.$result["datetime"].'</td>
    <td width="20%">&pound;'.$result["total"].'</td>
  </tr>';
}
?>
</table>

as you can see, there is a checkbox on each row that displays with the counter adding +1 each time.

I need a way for it to automatically add up the total column for what checkboxes are ticked and then display this total above or below the list.

Im not sure what javascript/jquery code it will be?

Anyone have any ideas, i would appreciate if you could give me a hand on this

thanks

share|improve this question
Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use pdo or mysqli. – hjpotter92 Apr 10 at 13:22

1 Answer

Quick example of how you easy handle multiple checkboxes:

<form action="" method="post" >
<input type="checkbox" name="boxes[]" value="1" />
<input type="checkbox" name="boxes[]" value="2" />
<input type="checkbox" name="boxes[]" value="3" />
<input type="submit" name="doit" />
</form>

<?php
    if(isset($_POST['doit'])) {
        $boxes = $_POST['boxes'];
        //loop through checked boxes
        foreach($boxes as $box) {
            //do your thing..
            print $box."<br />";
        }
    }
?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.