php - 如何在没有表格的情况下显示数据库中的产品?

标签 php html

我目前在我的灯数据库中有一个表,我想在其中显示产品。但是我已经展示了产品,但是页面看起来不专业。如何让页面更专业?我不想在表格中显示产品。

我已经在下面发布了我的代码:

<?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/

相关文章:

php - fscanf()/sscanf() - 匹配可变长度空白?

php - Laravel 4.1+ 中的环境检测

javascript - 在此 d3.js 日历 View 中包含 json?

html - 下拉过渡在 Safari 中不起作用

php - 如何更改 PHP 中的静态变量值?

php - 创建 iCal 事件,而不创建日历

php - 在过程编程中正确解释的哪种类型的代码在包含在类中(在函数之外)时会导致错误?

javascript - html中的复制命令用于chrome复制多个文本框

html - 如何使用相对路径访问文件

javascript - 计算网站中点击次数最多的视频