我目前在我的灯数据库中有一个表,我想在其中显示产品。但是我已经展示了产品,但是页面看起来不专业。如何让页面更专业?我不想在表格中显示产品。
我已经在下面发布了我的代码:
<?php
$con = mysql_connect("localhost","sam","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("products", $con);
$result = mysql_query("SELECT * FROM Products_table WHERE catid IN (1,2,7,8)");
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Image</th>
<th>Description</th>
<th>Contact Renter</th>
<th>Rent price</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['productname'] . "</td>";
echo "<td><img src='./images/products/".$row['productimage']."' width='150' height='100' alt=''></td>";
echo "<td>" . $row['productdescription'] . "</td>";
echo "<td>" . $row['rentersdetails'] . "</td>";
echo "<td>" . $row['rentprice'] . "</td>";
echo "</tr>";
echo <<<"buttons"
<td>
<input class="button_normal" type="button" value="Google Renter" onclick="window.open('https://www.google.co.uk/')"/>;
<input class="button_normal" type="button" value="Yahoo" onclick="window.open('https://www.yahoo.co.uk')"/>
</td>
buttons;
}
echo "</table>";
mysql_close($con);
?>
最佳答案
你可以把结果放在一个变量中:
<?php
$con = mysql_connect("localhost","sam","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("products", $con);
$result = mysql_query("SELECT * FROM Products_table WHERE catid IN (1,2,7,8)");
$results = array();
while($row = mysqli_fetch_assoc($query)){
$results[] = $row;
}
mysql_close($con);
?>
并像这样调用你的 $results 数组:
$results[0]['value']
或者在foreach中
foreach($results as $row => $value) {
//display your data however you like
}
关于php - 如何在没有表格的情况下显示数据库中的产品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29833572/