当数据长于列宽时,php 生成的 td 重叠数据

标签 php html css

我有以下生成的“详细信息”列

 echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque (' . $row4['number'] . ')'. $row1['date_added'] .'</td>';

这给了我下面的总体结果表,其中特定列数据在太长时会重叠。我应该怎么办?我试过添加 '<br/>'介于两者之间,但它从未奏效。 enter image description here

遗憾的是这张表没有外部 CSS 文件,但下面是完整的表

<table cellspacing="1" width="900" cellpadding="3" bgcolor="#CCCCCC" style="line-height:0px;margin-left: auto;margin-right: auto">
            <col width="64" span="10" />
            <tr height="46">
                <td height="46" width="600" colspan="10" bgcolor="#FFFFFF"><h1>Blah Blah</h1></td>               
            </tr>
            <?php
            include './DatabaseConnection.php';
            $db = new DatabaseConnection();
            $db->createDatabaseConnection();
            $cusid = $_GET['cusid'];
            $startDate=$_GET['startDate'];
            $endDate=$_GET['endDate'];

            $query2 = mysql_query("select cusname from customers where cusid='$cusid'");
            while ($row5 = mysql_fetch_array($query2)) {
                echo '<tr height="20" width="1000">
                <td height="10" colspan="10" bgcolor="#F3F3F3"><h2>Payment History of ' . $row5['cusname'] . ' (Credit)</h2></td>

            </tr><tr height="20">
                <td width="120" height="20" bgcolor="#FFFFFF"><h3>Date Added</h3></td>
                <td width="120" bgcolor="#FFFFFF"><h3 align="center">Invoice Number</h3></td>
                <td width="120" bgcolor="#FFFFFF"><h3 align="center">Invoice Amount</h3></td>
                <td width="120" bgcolor="#FFFFFF"><h3 align="center">Payed Amount</h3></td>
                <td width="120" bgcolor="#FFFFFF"><h3 align="center">Detail</h3></td>
                <td width="120" bgcolor="#FFFFFF"><h3 align="center">Balance</h3></td>
            </tr>';
            }

         //$query = mysql_query("SELECT * from payments where cusid ='$cusid'  and ingrtype = '1' and payment_status = '1' and (date_added >= '$startDate' and date_added <= '$endDate') order by invoiceGRN_id") or die(mysql_error());
         $query = mysql_query("SELECT * from payments where cusid ='$cusid'  and ingrtype = '1' and payment_status = '1' and (date_added >= '$startDate' and date_added <= '$endDate') order by invoiceGRN_id") or die(mysql_error());

            $lastinvoicenumber = null;

            while ($row1 = mysql_fetch_array($query)) {

                $invoiceAmount = $row1['subtotal'];
                $payedAmount = $row1['payment'];

                $invoicenumber = $row1['invoiceGRN_id'];
                $invoicetotal = 0;
                //$balanceAmount = $invoiceAmount - $payedAmount; 
                $balanceAmount = $invoiceAmount; 

                //diluk
                $queryinv = mysql_query("SELECT invoice_subtotal from invoice where invoice_number ='$invoicenumber' limit 1") or die(mysql_error());
                //diluk
                while ($rowinv = mysql_fetch_array($queryinv)) {

                    $invoicetotal = $rowinv['invoice_subtotal'];

                }


                echo '<tr height="20">
                <td width="100" align="left" bgcolor="#FFFFFF">' . $row1['date_added'] . '</td>';

                if($lastinvoicenumber!=$invoicenumber){
                echo '<td width="100" height="20" bgcolor="#FFFFFF">' . $row1['invoiceGRN_id'] . '</td>';
                echo '<td width="100" align="right" bgcolor="#FFFFFF">' . $invoicetotal . '</td>';
                }else{

                  echo '<td width="100" height="20" bgcolor="#FFFFFF"></td>';  
                  echo '<td width="100" align="right" bgcolor="#FFFFFF"></td>';  
                }




                echo '<td width="100" align="right" bgcolor="#FFFFFF">' . $row1['payment'] . '</td>';

                $invId = $row1['invoiceGRN_id'];
                if ($row1['paymentType'] == "Cheque") {
                    $query3 = mysql_query("select * from cheque where invoiceno='$invId'");
                    if ($row4 = mysql_fetch_array($query3)) {
                        echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque (' . $row4['number'] . ')'. $row1['date_added'] .'</td>';
                    }else{

                         echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque -' . $row1['date_added'] .'</td>';
                    }
                } else {
                    echo '<td width="100" align="left" bgcolor="#FFFFFF">' . $row1['paymentType'] . '</td>';
                }

                echo '<td width="100" align="right" bgcolor="#FFFFFF">' . $balanceAmount . '</td>
            </tr>';

                $lastinvoicenumber = $invoicenumber;
            }

            echo '<tr height="20" width="1000">
                <td height="10" colspan="10" bgcolor="#F3F3F3"><h2></h2></td></tr>';

            $queryx = mysql_query("SELECT * from invoice where customer_id ='$cusid' and payment_type !='Credit' group by invoice_number order by invoice_date") or die(mysql_error());
            while ($rowx = mysql_fetch_array($queryx)) {

                echo '<tr height="20">
                <td width="100" align="left" bgcolor="#FFFFFF">' . $rowx['invoice_date'] . '</td>
                <td width="100" height="20" bgcolor="#FFFFFF">' . $rowx['invoice_number'] . '</td>
                    <td width="100" height="20" bgcolor="#FFFFFF">' . $rowx['invoice_subtotal'] . '</td>
                <td width="100" height="20" bgcolor="#FFFFFF">' . $rowx['invoice_subtotal'] . '</td>';                               

                 $invId1 = $rowx['invoice_number'];
                if ($rowx['payment_type'] == "Cheque") {
                    $queryx1 = mysql_query("select * from cheque where invoiceno='$invId1'");
                    if ($rowx2 = mysql_fetch_array($queryx1)) {
                        echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque (' . $rowx2['number'] . ')</td>';
                    }
                } else {
                    echo '<td width="100" align="left" bgcolor="#FFFFFF">' . $rowx['payment_type'] . '</td>';
                }

                echo '<td width="100" align="right" bgcolor="#FFFFFF">0</td>
            </tr>';
            }

            ?>
        </table>

最佳答案

您必须考虑两件事:

1. table-layout: fixed; this for table, and

2. word-wrap: break-word;td 本身。

详细请看这个问题:How to force table cell <td> content to wrap?

关于当数据长于列宽时,php 生成的 td 重叠数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23468487/

相关文章:

html - 悬停时的 Bootstrap 下拉菜单(使用 Creative-Tim 图标导航栏)

php - 如何从js代码中获取字符串值

javascript - JS/jQuery 中的缩放幻灯片

jquery - 为什么这些 jQuery 对象不起作用?

html - 多个类选择器不应用属性

html - AngularJS 将 css 设置为指令中的标记(Bootstrap 粘性页脚)

css - 似乎无法让提交/按钮/ anchor 排队

php - 有人知道 pfsockopen() 周围的 SSH/SFTP/FTP 包装器吗?

php - 如何通过循环将php数组中对象的值写入mysql

javascript - 无法通过 JQuery 访问选择框