我已经编写了一个可以使用 PHP 从 mysql 保存数据的代码,那么如何使用 CSS 样式的表格来显示它。存储在我的服务器中的数据是:产品名称、产品规格、价格和产品图片链接。如何以这种格式显示所有这些:
这是它的源代码:
<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> </td>
<td>
<img src="img/prd1.jpg" />
</td>
<td> </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> </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> </td>
<td>
<img src="img/prd2.jpg" />
</td>
<td> </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> </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> </td>
<td>
<img src="img/prd3.jpg" />
</td>
<td> </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> </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> </td>
<td>
<img src="img/prd4.jpg" />
</td>
<td> </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> </td>
<td>
<img src="img/prd8.jpg" />
</td>
</tr>
<tr><td><br /><br /></td></tr>
</table>
</div>
</div>
</body>
我知道它需要循环来打印 mysql 表中的所有行,但它有多个单元格,我必须使用嵌套循环来打印吗?