php mysql库数组排序

php mysql库数组排序,php,html,mysql,css,web,Php,Html,Mysql,Css,Web,我一直在尝试将数据库中的图像排序为产品网格列表,如下所示: 我不知道我的代码要改什么我被卡住了。我需要帮助,请,我试图创建一个在线商店 这是我的密码: <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Run a select query to get my letest 6 items // Connect to the

我一直在尝试将数据库中的图像排序为产品网格列表,如下所示:

我不知道我的代码要改什么我被卡住了。我需要帮助,请,我试图创建一个在线商店

这是我的密码:

<?php 

// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php 
// Run a select query to get my letest 6 items
// Connect to the MySQL database  
include "storescripts/connect_to_mysql.php"; 
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 4");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
  while($row = mysql_fetch_array($sql)){ 
        $id = $row["id"];
       $product_name = $row["product_name"];
       $price = $row["price"];
       $row = 3;
       $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
       $dynamicList .= '<table width="100" border="0" cellspacing="0" cellpadding="6">
        <tr>
          <td width="100%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width=200" height="150" border="1" /></a></td>
          <td width="100%" valign="top">' . $product_name . '<br />
            $' . $price . '<br />
            <a href="product.php?id=' . $id . '">View Product</a></td>
        </tr>
      </table>';
    }
} else {
  $dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Store Home Page</title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="mainWrapper">
  <?php include_once("template_header.php");?>
  <div id="pageContent">
  <table width="100%" border="0" cellspacing="0" cellpadding="10">
  <tr>
    <td width="32%" valign="top"><h3>&nbsp;</h3></td>
    <td width="35%" valign="top"><h3>Latest Designer Fashions</h3>
      <p><?php echo $dynamicList; ?><br />
        </p>

      <p><br />
      </p></td>
    <td width="33%" valign="top"><h3>Handy Tips</h3>
      <p>If you operate any store online you should read the documentation provided to you by the online payment gateway you choose for handling the checkout process. You can get much more insight than I can offer on the various details of a gateway, from the gateway providers themselves. They are there to help you with whatever you need since they get a cut of your online business dealings.</p></td>
  </tr>
</table>

  </div>
  <?php include_once("template_footer.php");?>
</div>
</body>
</html>

存储主页
最新设计师时装


方便的小贴士 如果您经营任何在线商店,您应该阅读您选择的用于处理结帐过程的在线支付网关提供给您的文档。您可以从网关提供商本身获得比我提供的更多关于网关的各种细节的见解。他们会帮你做任何你需要的事情,因为他们会从你的网上交易中分得一杯羹


从代码中删除
$row=3
以使用
$row[“添加日期”]
并为每个产品记录创建表

$dynamicList='We have no products listed in our store yet';
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 4");

$productCount = mysql_num_rows($sql); // count the output amount
    if ($productCount > 0) {
        $dynamicList='<table width="100" border="0" cellspacing="0" cellpadding="6">';

        while ($row = mysql_fetch_array($sql)) {
            $id = $row["id"];
            $product_name = $row["product_name"];
            $price = $row["price"];
            $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
            $dynamicList.= 'tr><td width="100%" valign="top"><a href="product.php?id=' . $id . '">'
                        .'<img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width=200" height="150" border="1" />
                        </a></td><td width="100%" valign="top">' . $product_name . '<br />
                         $' . $price . '<br /><a href="product.php?id=' . $id . '">View Product</a></td>
                        </tr>';
        }

        $dynamicList.='</table>';
    } 

    echo $dynamicList;
$dynamicList='我们的商店还没有列出任何产品';
$sql=mysql\u查询(“按日期从产品订单中选择*添加描述限制4”);
$productCount=mysql_num_rows($sql);//计算输出量
如果($productCount>0){
$dynamicList='';
while($row=mysql\u fetch\u数组($sql)){
$id=$row[“id”];
$product_name=$row[“product_name”];
$price=$row[“price”];
$date\u added=strftime(“%b%d,%Y”,strotime($row[“date\u added”]);
$dynamicList.='tr>。$product\u name.
$。$价格。'
'; } $dynamicList.=''; } echo$dynamicList;
您的链接图像有8个图像,但您的查询有
限制4
?我删除了$row=3,但它仍然按降序抓取图像,我希望它看起来像这样…相反,它看起来像这样,在foreach loopno我没有。我的代码看起来是一样的。我的表在php代码中的php:$dynamicList.=''下$产品名称。”
$”$价格。”
;这就是我必须删除$dynamiclist下的表的位置。=?再次感谢您的帮助