0

i am trying to display MySQL Data using PHP in a HTML Table. the rows are currently clickable and the checkbox puts a number from the data into a textbox and then adds on each checkbox you tick.

I want to keep this however when you single click the row it will check the box and put the number into the textbox (like it does when the text box is checked)

then if the row is double clicked it will open a new webpage

here is my current PHP Code:

<script>
function correctNumber(number) {
    return (parseFloat(number.toPrecision(12)));
}

function add(total, this_chk_bx) {
    var thetotal = (form2.thetotal.value * 1);
    var total = total * 1;


    if (this_chk_bx.checked == true) {
        //add if its checked
        form2.thetotal.value = correctNumber(thetotal + total);
    } else {
        //subtract if its unchecked
        form2.thetotal.value = correctNumber(thetotal - total);
    }
}
</script>

<form name="form2">
  <table width="100%" border="0" cellspacing="0" cellpadding="10">
  <tr>
    <td colspan="6"><form action="../">
    <select name="status" onchange="window.open(this.options[this.selectedIndex].value,'_top')">
    <option value="?status=" <?php if($_GET["status"] == '') { echo 'selected="selected"'; } ?>>Not Paid</option>
    <?php
    $sql2="SELECT * from billing_pdf_archive where status <> '' group by status ";
    $rs2=mysql_query($sql2,$conn) or die(mysql_error());
    while($result2=mysql_fetch_array($rs2))
    {
        echo ('<option value="?status='.$result2['status'].'"');
        if(($_GET['status']) == ($result2['status'].''))
        {
            echo (' selected ');
        }
        echo ('>'.$result2['status'].'</option>');
        }
    ?>
    </select>
    </form>
  </tr>
  <tr>
    <td width="20">&nbsp;</td>
    <td width="150"><strong><?php echo $invoicenumber_link; ?></strong></td>
    <td width="250"><strong><?php echo $company_link; ?></strong></td>
    <td width="100"><strong><?php echo $date_link; ?></strong></td>
    <td width="100"><strong><?php echo $total_link; ?></strong></td>
    <td width="100">&nbsp;</td>
  </tr>
<?php
$rs=mysql_query($sql,$conn) or die(mysql_error());
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"];
    }

    $total = $result["total"];

    $date = date("d/j/Y",strtotime($result['datetime']));

    echo '<tr class="notfirst" style="cursor:pointer;" onclick="document.location=\'editinvoice.php?seq='.$result["sequence"].'&inv='.$result["invoice_number"].'\'">
                <td width="20"><input type="checkbox" name="check'.$counter.'" id="check'.$counter.'" onclick=\'add('.$total.', this);\' /></td>
                <td width="150">'.$result["invoice_number"].'</td>
                <td width="250">'.$company.'</td>
                <td width="100">'.$date.'</td>
                <td width="100">&pound;'.$result["total"].'</td>
                <td width="100">&pound;'.$result["total"].'</td>
            </tr>';
}
?>
<tr>
    <td colspan="6">&nbsp;</td>
</tr>
<tr>
    <td colspan="6">&nbsp;</td>
</tr>
</table>

<div class="div-bottom">
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
    <td>&nbsp;</td>
    <td><strong>Total: </strong><input type="text" name="thetotal" value="0" /></td>
    <td><strong>VAT:</strong> </td>
  </tr>
</table>
</div>
</form>

any ideas the best way round this?

4
  • You have no problem with php or mysql. This is a javascript/DOM manipulation and usability problem. Well, it I show you how to make a take with clickable rows that activates a checkbox e 2-click open a new window, will it solve your problem? Commented Jun 27, 2013 at 21:16
  • it certainly will - i need the single click to do what the checkbox does so when a row is clicked it puts the number(price) in a textbox then another row is selected and it adds that row to the selected one and so on... then when un selected it will remove that number from the textbox Commented Jun 27, 2013 at 21:18
  • 2
    Obligatory: The mysql_* functions will be deprecated in PHP 5.5. It is not recommended for writing new code as it will be removed in the future. Instead, either the MySQLi or PDO and be a better PHP Developer. Commented Jun 27, 2013 at 21:22
  • 1
    @leonardo_assumpcao 90% of newbie PHP programmers without any prior programming experience have something against OOP. the problem is that may cover most PHP programmers in general ... Commented Jun 27, 2013 at 21:23

1 Answer 1

1

Take a look at jQuery .click and .dblclick event handlers.

  1. http://api.jquery.com/dblclick/
  2. http://api.jquery.com/click/

If you don have any jquery knowledge, try.jquery.com

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.