【问题标题】:Mysql Database - Need 3 equal columnsMysql 数据库 - 需要 3 个相等的列
【发布时间】:2017-02-26 14:05:14
【问题描述】:

我有来自 mysql 数据库的 3 列的结果。列具有正确的信息,但是列数据都被压缩在一起,正如您在http://althedge.xyz/index2.html 看到的那样,我对 html 知之甚少,并试图让列在页面上均匀分布。谁能告诉我如何做到这一点?谢谢

代码如下:

<?php

// Database Settings 
define('DB_HOST', 'localhost');
define('DB_PORT', '3306');
define('DB_USER', '*****');
define('DB_PASS', '*****');
define('DB_NAME', '*****');

// Connection to Database
$database = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);

$sql = 'SELECT * '
        . ' FROM posts';

$resultSet = $database->query($sql);


// Begin building some HTML output

$html = '<table border="0">
<tr>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
</tr>';

while ($row = $resultSet->fetch_assoc())
{
$html .= '<tr>';
$html .= '<td>' . $row['Column1'] . '</td>';
$html .= '<td>' . $row['Column2'] . '</td>';
$html .= '<td>' . $row['Column3'] . '</td>';
$html .= '</tr>';
}

$html .= '</table>';
echo $html;

?>

【问题讨论】:

  • 我可以发誓我看到了一个与 1-2 小时前发布的非常相似的问题。

标签: html mysql multiple-columns


【解决方案1】:

使用

<table border="0" style="width: 100%;">

使表格跨越页面的整个宽度。请注意,列的大小仍然不同。

要使所有列的间距相等,您可以使用

<table border="0" style="width: 100%; table-layout: fixed;">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 2022-07-04
    • 1970-01-01
    相关资源
    最近更新 更多