[英]Php column table width
我正在嘗試使列的寬度相同,當我有空列時,它們的大小正確,但是當我從MySQL數據庫插入表時,它們會發生變化,並且一列比其他列大,一列名為“ BristolQualification”。 我認為這可能與實際表有關,因為我嘗試過移動BristolQualification
,並且每個不同的列中的大小都相同。 有兩項BathQualification
因為我只是在玩耍和測試。 有誰知道為什么會這樣? 我嘗試用width="25%"
替換它們(因為有4列25 * 4 = 100%)。
<?php
mysql_connect("host", "user", "pwd") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$data = mysql_query("
SELECT
`Bath`.`BathCountry` ,
`Bristol`.`BristolCountry` ,
`Bath`.`BathQualification` ,
`Bristol`.`BristolQualification`
FROM
`Bristol`
LEFT JOIN
`Bath`
ON
`Bristol`.`BristolCountry` = `Bath`.`BathCountry`
ORDER BY
`Bristol`.`BristolCountry`;
")
or die(mysql_error());
Echo "<table class=\"imagetable\" border cellpadding=3 style=\"width:100%;\">";
while($info = mysql_fetch_array( $data ))
{
Echo "<tr>";
Echo "<th width=\"100\">Country:</th>
<th class=\"Bristol\" width=\"100\">Qualifications to Bristol:</th>
<th class=\"USW\" width=\"100\">Qualifications to USW:</th>
<th class=\"Bath\" width=\"100\">Qualifications to Bath:</th>";
Echo "</tr>";
Echo "<tr>";
Echo "<td width=\"100\">".$info['BristolCountry'] . "</td>
<td class=\"Bristol2\" width=\"100\">".$info['BathQualification'] . " </td>
<td class=\"Bath2\" width=\"100\">".$info['BathQualification'] . " </td>
<td class=\"USW2\" width=\"100\">".$info['BristolQualification'] . " </td> " ;
Echo "</tr>";
}
Echo "</table>";
?>
發生此問題是因為變量字符串長度不相等。我在上一年也遇到過類似問題。您可以按照以下說明解決此問題。
大段引用
$info['BathQualification']
$info['BathQualification']
$info['BristolQualification']
Are not all the same size in length. Guess the strings length are l1, l2, l3 respectively. So
determine that which one is bigger.Suppose that you have determind that l2>l1>l2 .
Then add :
(l2-l1) spaces with $info['BathQualification']
(l2-l2) spaces with $info['BathQualification']
(l2-l3) spaces with $info['BristolQualification']
現在享受。
您應該使用以下CSS屬性: word-break:break-all; word-wrap:break-word
word-break:break-all; word-wrap:break-word
(強制您的內容適合塊的寬度)和table-layout:fixed
在表上。
table {
word-break:break-all;
word-wrap:break-word;
table-layout:fixed;
}
嘗試這個:
Echo "<table class=\"imagetable\" border cellpadding=3 style=\"width:100%;\">";
while($info = mysql_fetch_array( $data ))
{
Echo "<tr>";
Echo "<th width=\"100\">Country:</th>
<th class=\"Bristol\" width=\"33%\">Qualifications to Bristol:</th>
<th class=\"USW\" width=\"33%\">Qualifications to USW:</th>
<th class=\"Bath\" width=\"33%\">Qualifications to Bath:</th>";
Echo "</tr>";
Echo "<tr>";
Echo "<td width=\"100\">".$info['BristolCountry'] . "</td>
<td class=\"Bristol2\">".$info['BathQualification'] . " </td>
<td class=\"Bath2\">".$info['BathQualification'] . " </td>
<td class=\"USW2\">".$info['BristolQualification'] . " </td> " ;
Echo "</tr>";
}
Echo "</table>";
還要確保內容不占用所有td的空間,因此,如果td的寬度為100px(不包含內容),請確保其內容不超過100px
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.