gpt4 book ai didi

PHP 回显表及其 CSS

转载 作者:太空宇宙 更新时间:2023-11-04 02:58:48 25 4
gpt4 key购买 nike

我真的需要你的帮助。我正在尝试从我的数据库中回显一个表,但它首先带有我不想要的数据库中的表名,而且 css 很奇怪。我希望我的表格在每一列中都有不同的标题,然后数据以统一的方式显示在相应列标题的下方。

php代码在这里

    <div id="content-1">
<div>
<?php

$table = 'std_details';
// sending query for table
$result = mysql_query("SELECT * FROM {$table}");

if (!$result) {

die ("Query to show fields from table failed");

}

$fields_num = mysql_num_fields($result);

echo "<h1>All Students</h1>";
echo "<table border='2' class='gridtable'><tr>";

// printing table headers
for ($i=0; $i < $fields_num; $i++) {

$field = mysql_fetch_field($result);
echo "<td>{$field->name}&nbsp;&nbsp;</td>";

}

echo "</tr>\n";

// printing table rows
while ($row = mysql_fetch_row($result)) {

echo "<tr>";

// $row is array.... foreach( .. ) puts every element
// of $row to $cell variable
foreach ($row as $cell) {

echo "<td>&nbsp;\t$cell</td>";

}
echo "</tr>\n";
}

mysql_free_result($result)
?>
</div>
</div>

表格的CSS是

    table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}

谢谢大家。我真的需要帮助!

enter image description here

最佳答案

我不明白为什么你使用 mysql 而不是 mysqli 无论如何这可能对你有帮助

  <!DOCTYPE html>
<html>
<head>
<style>
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}

</style>
<!--- uncomment these line if you are loading css from external file --->
<!--- <link href="Your css file" rel="stylesheet"> --->
</head>
<div id="content-1">
<div>
<?php

$table = 'std_details';
// sending query for table
$result = mysql_query("SELECT * FROM {$table}");

if (!$result) {

die ("Query to show fields from table failed");

}

$fields_num = mysql_num_fields($result);

echo "<h1>All Students</h1>";
echo "<table border='2' class='gridtable'><tr>";

// printing table headers
for ($i=0; $i < $fields_num; $i++) {

$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";

}

echo "</tr>";

// printing table rows
while ($row = mysql_fetch_row($result)) {

echo "<tr>";

// $row is array.... foreach( .. ) puts every element
// of $row to $cell variable
foreach ($row as $cell) {

echo "<td>&nbsp;\t$cell</td>";

}
echo "</tr>";
}
echo "</table>";

mysql_free_result($result)
?>
</div>
</div>

关于PHP 回显表及其 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31671880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com