gpt4 book ai didi

php - 以样式显示来自 Mysql 表的数据

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

我已经编写了一个代码,可以使用 PHP 保存来自 mysql 的数据,那么如何使用 CSS 样式表来显示它。我的服务器中存储的数据是:产品名称、产品规范、价格和产品图片链接。我怎样才能用这种格式显示所有这些:

Table Format

这是它的源代码:

  <body>

<div class="gridContainer clearfix">
<div id="LayoutDiv1">
<center><font color="White" size="+12"><u>PROCESSORS</u></font></center>
<table border=0 align="center">
<th colspan="3"><h2><font color="White">AMD PROCESSORS</font></h2></th>
<th></th>
<th colspan="3"><h2><font color="White">INTEL PROCESSORS</font></h2></th>
<tr><td>
<form action=cds.php method=get>
<table border="0" bordercolorlight="#FFFF99">
<th align="center" colspan="2" bgcolor="#FF9900"> AMD ATHLON II X2 260</th>
<tr><td >Specs:</td><td>3.20Ghz<br />2 cores<br />2Mb Cache<br />Supports x86 and x64
OS<br />w/ Cool'n Quiet Tech</td></tr>
<tr><td >Price:</td><td>2500</td></tr>
<tr><td >Quantity:</td><td><input type=text name=quant></td></tr>
<tr><td >Add to cart?</td><td ><input type="submit" value="Yes"></td></tr>
</table>
<input type=hidden name=comp value="AMD">
<input type=hidden name=prdname value="AMD ATHLON II X2 260">
<input type=hidden name=prc value="2500">
</form>
</td>
<br />
<td>&nbsp;&nbsp;&nbsp;</td>
<td>
<img src="img/prd1.jpg" />
</td>

<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<form action=cds.php method=get>
<table border="0" bordercolorlight="#FFFF99">
<th align="center" colspan="2" bgcolor="#FF9900">INTEL i3</th>
<tr><td >Specs:</td><td >3.20Ghz<br />2 cores<br />3Mb Cache<br />Supports x86 and x64
OS<br />w/ Cool'n Quiet Tech</td></tr>
<tr><td >Price:</td><td >2500</td></tr>
<tr><td >Quantity:</td><td ><input type=text name=quant></td></tr>
<tr><td >Add to cart?</td><td ><input type="submit" value="Yes"></td></tr>
</table>
<input type=hidden name=comp value="INTEL">
<input type=hidden name=prdname value="INTEL i3">
<input type=hidden name=prc value="2500">
</form>
</td>
<br />
<td>&nbsp;&nbsp;&nbsp;</td>
<td>
<img src="img/prd5.jpg" />
</td>
</tr>
<tr><td>
<form action=cds.php method=get>
<table border="0" bordercolorlight="#FFFF99">
<th align="center" colspan="2" bgcolor="#FF9900">AMD SEMPRON</th>
<tr><td >Specs:</td><td >2.20Ghz<br />4 cores<br />4Mb Cache<br />Supports x86 and x64
OS<br />w/ Cool'n Quiet Tech</td></tr>
<tr><td >Price:</td><td >3000</td></tr>
<tr><td >Quantity:</td><td ><input type=text name=quant></td></tr>
<tr><td >Add to cart?</td><td ><input type="submit" value="Yes"></td></tr>
</table>
<input type=hidden name=comp value="AMD">
<input type=hidden name=prdname value="AMD SEMPRON">
<input type=hidden name=prc value="3000">
</form>
</td>
<br />
<td>&nbsp;&nbsp;&nbsp;</td>
<td>
<img src="img/prd2.jpg" />
</td>

<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<form action=cds.php method=get>
<table border="0" bordercolorlight="#FFFF99">
<th align="center" colspan="2" bgcolor="#FF9900">INTEL i5</th>
<tr><td >Specs:</td><td >3.40Ghz<br />4 cores<br />6Mb Cache<br />Supports x86 and
x64 OS<br />w/ Cool'n Quiet Tech</td></tr>
<tr><td >Price:</td><td >5500</td></tr>
<tr><td >Quantity:</td><td ><input type=text name=quant></td></tr>
<tr><td >Add to cart?</td><td ><input type="submit" value="Yes"></td></tr>
</table>
<input type=hidden name=comp value="INTEL">
<input type=hidden name=prdname value="INTEL i5">
<input type=hidden name=prc value="5500">
</form>
</td>
<br />
<td>&nbsp;&nbsp;&nbsp;</td>
<td>
<img src="img/prd6.jpg" />
</td>

</tr>
<tr><td>
<form action=cds.php method=get>
<table border="0" bordercolorlight="#FFFF99">
<th align="center" colspan="2" bgcolor="#FF9900">AMD PHENOM II x6</th>
<tr><td >Specs:</td><td >3.7 GHz<br />6 cores<br />6Mb Cache<br />Supports x86 and
x64 OS<br />w/ Cool'n Quiet Tech</td></tr>
<tr><td >Price:</td><td >4500</td></tr>
<tr><td >Quantity:</td><td ><input type=text name=quant></td></tr>
<tr><td >Add to cart?</td><td ><input type="submit" value="Yes"></td></tr>
</table>
<input type=hidden name=comp value="AMD">
<input type=hidden name=prdname value="AMD PHENOM II x6">
<input type=hidden name=prc value="4500">
</form>
</td>
<br />
<td>&nbsp;&nbsp;&nbsp;</td>
<td>
<img src="img/prd3.jpg" />
</td>

<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<form action=cds.php method=get>
<table border="0" bordercolorlight="#FFFF99">
<th align="center" colspan="2" bgcolor="#FF9900">INTEL i7</th>
<tr><td >Specs:</td><td >4.0Ghz<br />4 cores<br />8Mb Cache<br />Supports x86 and x64
OS<br />w/ Cool'n Quiet Tech</td></tr>
<tr><td >Price:</td><td >6500</td></tr>
<tr><td >Quantity:</td><td ><input type=text name=quant></td></tr>
<tr><td >Add to cart?</td><td ><input type="submit" value="Yes"></td></tr>
</table>
<input type=hidden name=comp value="INTEL">
<input type=hidden name=prdname value="INTEL i7">
<input type=hidden name=prc value="6500">
</form>
</td>
<br />
<td>&nbsp;&nbsp;&nbsp;</td>
<td>
<img src="img/prd7.jpg" />
</td>

</tr>
<tr><td>
<form action=cds.php method=get>
<table border="0" bordercolorlight="#FFFF99">
<th align="center" colspan="2" bgcolor="#FF9900">AMD OPTERON x16</th>
<tr><td >Specs:</td><td >3.30Ghz<br />16 cores<br />2Mb Cache<br />Supports x86 and
x64 OS<br />w/ Cool'n Quiet Tech</td></tr>
<tr><td >Price:</td><td >7500</td></tr>
<tr><td >Quantity:</td><td ><input type=text name=quant></td></tr>
<tr><td >Add to cart?</td><td ><input type="submit" value="Yes"></td></tr>
</table>
<input type=hidden name=comp value="AMD">
<input type=hidden name=prdname value="AMD OPTERON x16">
<input type=hidden name=prc value="7500">
</form>
</td>
<br />
<td>&nbsp;&nbsp;&nbsp;</td>
<td>
<img src="img/prd4.jpg" />
</td>

<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<form action=cds.php method=get>
<table border="0" bordercolorlight="#FFFF99">
<th align="center" colspan="2" bgcolor="#FF9900">INTEL PENTIUM 4 G870</th>
<tr><td >Specs:</td><td >3.20Ghz<br />2 cores<br />2Mb Cache<br />Supports x86 and
x64 OS<br />w/ Cool'n Quiet Tech</td></tr>
<tr><td >Price:</td><td >3500</td></tr>
<tr><td >Quantity:</td><td ><input type=text name=quant></td></tr>
<tr><td >Add to cart?</td><td ><input type="submit" value="Yes"></td></tr>
</table>
<input type=hidden name=comp value="INTEL">
<input type=hidden name=prdname value="INTEL PENTIUM G870">
<input type=hidden name=prc value="3500">
</form>
</td>
<br />
<td>&nbsp;&nbsp;&nbsp;</td>
<td>
<img src="img/prd8.jpg" />
</td>

</tr>
<tr><td><br /><br /></td></tr>
</table>
</div>
</div>
</body>

我知道它需要循环来打印 mysql 表中的所有行,但它有多个单元格,我是否必须使用嵌套循环来打印它?

最佳答案

你呈现的是一个循环,所以使用一个循环(甚至多个)。将所有这些值插入到数据库行中,添加必要的列并使用 WHILE LOOP 获取数据。在循环中只包含一个表格 html,这样您就不会重复代码。

The faster way is to create a function with the product name fetching the data from the db. That will save you a lot of time

Correct the forms, closing the quotation on the input field

<input type=hidden name="comp" value="">
<input type=hidden name="prdname" value="">
<input type=hidden name="prc" value="">

and <form action="cds.php" method="get">
(for this need, I would prefer method POST)

关于php - 以样式显示来自 Mysql 表的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15874603/

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