gpt4 book ai didi

php - 我如何将此 SQLDatabase 数据回显到程式化表格中?

转载 作者:行者123 更新时间:2023-11-30 23:33:47 25 4
gpt4 key购买 nike

我正在尝试将 SQL 数据库中的数据回显到一个看起来还不错的表中。我已经可以将数据正确地回显到 5 个单独的基本表中,但是当我无法弄清楚如何在不完全搞砸的情况下设置它的样式时。这是我已有的代码:

    // OUTPUTS RESULTS //

$resultfirst = mysql_query("SELECT * FROM Students WHERE FirstPeriod='$_POST[firstperiod]'");
$resultsecond = mysql_query("SELECT * FROM Students WHERE SecondPeriod='$_POST[secondperiod]'");
$resultthird = mysql_query("SELECT * FROM Students WHERE ThirdPeriod='$_POST[thirdperiod]'");
$resultfourth = mysql_query("SELECT * FROM Students WHERE FourthPeriod='$_POST[fourthperiod]'");
$resultfifth = mysql_query("SELECT * FROM Students WHERE FifthPeriod='$_POST[fifthperiod]'");


// 1st PERIOD

echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>First Period</th>
</tr>";

while($row = mysql_fetch_array($resultfirst))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";



// 2nd PERIOD

echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Second Period</th>
</tr>";

while($row = mysql_fetch_array($resultsecond))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";



// 3rd PERIOD

echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Third Period</th>
</tr>";

while($row = mysql_fetch_array($resultthird))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";



// 4th PERIOD

echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Fourth Period</th>
</tr>";

while($row = mysql_fetch_array($resultfourth))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";




// 5th PERIOD

echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Fifth Period</th>
</tr>";

while($row = mysql_fetch_array($resultfifth))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";

如果上面的代码不清楚 - 我的目标是比较存储在数据库中的第一期教师,并输出具有相同时期/教师的学生姓名。此代码工作正常。但是 table 看起来很平淡。我想将数据回显到这样的表格中。

<table width="368" border="0" cellspacing="0" cellpadding="2" align="center" height="100">
<tr valign="middle">
<td bgcolor="#000066" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Services</font></b></font> </div>
</td>
<td width="4" height="20"></td>
<td bgcolor="#990000" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Products</font></b></font></div>
</td>
<td width="4" height="20"></td>
<td bgcolor="#C89800" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Resources</font></b></font> </div>
</td>
</tr>
<tr valign="top">
<td bgcolor="#000066" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Professional
and cost effective web design, development and promotion services
</font></p>
</td>
</tr>
</table>
</td>
<td width="4"></td>
<td bgcolor="#990000" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Interactive
Web Products - Flash Survey, poll, Guest book, Instant Quote

</font></p>
</td>
</tr>
</table>
</td>
<td width="4"></td>
<td bgcolor="#C89800" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Free
web resources - articles, tutorials, tips and tricks.
</font></p>
</td>
</tr>
</table>
</td>
</tr>
</table>

如果有人可以提供任何类型的建议,我将不胜感激。

最佳答案

我看到了一些可以改进的地方:

  • 正如其他人所说,不要使用表格来管理布局。但是,表格完全可以用于显示表格数据
  • 您确实想使用 CSS 来设计您的页面样式,这样可以更轻松地控制您的样式并使标记更易于阅读。在 CSS Tables 上查看 w3schools 的文章
  • 您可以将多个查询合并为一个以获得更好的性能(尽管这似乎超出了您的问题范围)

这是您表格的示例标记和 CSS:http://jsfiddle.net/vxzJV/

关于php - 我如何将此 SQLDatabase 数据回显到程式化表格中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9241993/

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