在首页显示最新订单的方法。

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家

效果如下:

1.在相对应的模板PHP文件内加入以下代码:
  1. //获取最新订单
  2. $sql_order_goods = "SELECT g.goods_id , o.user_id FROM " . $ecs->table("order_goods") . " AS g
  3. RIGHT JOIN ". $GLOBALS['ecs']->table("order_info") . " AS oON o.order_id = g.order_id ORDER BY O.add_time DESC LIMIT 0,3";
  4. $order_goods= $db->getALL($sql_order_goods);

  5. foreach ($order_goods AS $key=>$val)
  6. {
  7. $goods_id = $order_goods[$key]['goods_id'];
  8. $user_id= $order_goods[$key]['user_id'];

  9. $sql = "SELECT goods_name, goods_thumb FROM " . $ecs->table("goods") . " WHERE goods_id= $goods_id";
  10. $goods = $db->getALL($sql);

  11. $sql2= "SELECT user_name FROM " . $ecs->table("users") . " WHERE user_id = $user_id";
  12. $user_name= $db->getALL($sql2);

  13. foreach ($goods as $key2=>$val2)
  14. {
  15. $order_goods[$key]['goods_name']= $goods[$key2][goods_name];
  16. $order_goods[$key]['goods_thumb']= $goods[$key2][goods_thumb];
  17. }

  18. foreach ($user_name as $key3=>$val3)
  19. {
  20. $order_goods[$key]['user_name']= $user_name[$key3][user_name];
  21. }
  22. }

  23. $smarty->assign('order',$order_goods);
复制代码


2.在模板中加入循环即可
  1. <div class="index_order left">
  2. <div class="index_ordertitle"><span>最新订单</span><!--<a href="#" class="more">更多...</a>--></div>
  3. <ul class="index_order_box">
  4. {foreach from=$order item=order}
  5. <li>
  6. <a href="goods.php?id={$order.goods_id}" class="aimg">
  7. <img src="{$order.goods_thumb}" width="60" height="60" /></a>
  8. <p class="cpname">{$order.goods_name}</p>
  9. <p class="cppj">用户:{$order.user_name|truncate:4:"***":true}</p>
  10. </li>
  11. {/foreach}
  12. </ul>
  13. </div>
复制代码



回答:
这个教程还挺有用

谢谢分享~~

不错!

ECSHOP学习资料:http://www.phpally.com

不错 在首页显示最新订单的方法