【问题标题】:PHP MySQL display data with clickable table rowsPHP MySQL 用可点击的表格行显示数据
【发布时间】:2013-06-27 21:11:37
【问题描述】:

我正在尝试在 HTML 表中使用 PHP 显示 MySQL 数据。这些行当前是可点击的,复选框将数据中的一个数字放入文本框中,然后在您勾选的每个复选框上添加。

我想保留它,但是当您单击该行时,它将选中该框并将数字放入文本框中(就像选中文本框时一样)

然后如果双击该行,它将打开一个新网页

这是我当前的 PHP 代码:

<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>

有什么想法可以解决这个问题吗?

【问题讨论】:

  • 你用php或者mysql都没有问题。这是一个 javascript/DOM 操作和可用性问题。好吧,我将向您展示如何使用可点击的行来激活复选框 e 2-单击打开一个新窗口,它会解决您的问题吗?
  • 它肯定会 - 我需要单击来执行复选框的操作,因此当单击一行时,它将数字(价格)放入文本框中,然后选择另一行并将该行添加到选定的,依此类推...然后当取消选择时,它将从文本框中删除该数字
  • 强制: mysql_* 函数将是 deprecated in PHP 5.5。不建议编写新代码,因为它会在未来被删除。相反,MySQLiPDObe a better PHP Developer
  • @leonardo_assumpcao 90% 的没有任何编程经验的 新手 PHP 程序员都反对 OOP。问题是它可能涵盖了大多数 PHP 程序员...

标签: php javascript html mysql


【解决方案1】:

看看 jQuery .click 和 .dblclick 事件处理程序。

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

如果您没有任何 jquery 知识,try.jquery.com

【讨论】:

    猜你喜欢
    • 2013-09-21
    • 1970-01-01
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    • 1970-01-01
    • 2010-12-15
    • 2017-12-22
    • 1970-01-01
    相关资源
    最近更新 更多