dua55014 2015-06-21 03:14
浏览 97

php mysql gallery数组排序

I Have been trying to sort my images from my database in as a product grid list shown here:

https://www.woothemes.com/wp-content/uploads/2012/08/Mystile-WooCommerce-Homepage-Grid.png...

I don't know what to change in my code I'm stuck. I need help please, Im trying to create an online store.

heres my code:

<?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>
  • 写回答

1条回答 默认 最新

  • doutiaosu2310 2015-06-21 03:37
    关注

    remove $row = 3 from your code to use $row["date_added"] and you creating table for each product record .

    $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;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集