如何在首页和,产品列表页显示,会员等级对应的价格

2016-07-07 15:05 来源:www.chinab4c.com 作者:ecshop专家

帮顶。。。。。。。

回答:
我也想知道!咋没人回呢?

产品后台不是本来就有这个功能的

  1. /**

  2. * 获得指定商品的各会员等级对应的价格

  3. *

  4. * @accesspublic

  5. * @paraminteger$goods_id

  6. * @returnarray

  7. */

  8. function get_user_rank_prices_bast()

  9. {

  10. $sqlg="SELECT goods_id, shop_price FROM". $GLOBALS['ecs']->table('goods'). "ORDER BY goods_id DESC";

  11. $resg = $GLOBALS['db']->query($sqlg);



  12. while ($row = $GLOBALS['db']->fetchRow($resg))

  13. {



  14. $shop_price = $row['shop_price'];

  15. $goods_id= $row['goods_id'];



  16. //echo$shop_price."<br>";



  17. $sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $shop_price/ 100) AS price, r.rank_name, r.discount " .

  18. 'FROM ' . $GLOBALS['ecs']->table('user_rank') . ' AS r ' .

  19. 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp ".

  20. "ON mp.goods_id = '$goods_id' AND mp.user_rank = r.rank_id " .

  21. "WHERE r.show_price = 1 OR r.rank_id = '$_SESSION[user_rank]'";

  22. $res = $GLOBALS['db']->query($sql);

  23. $arr = array();

  24. while ($row = $GLOBALS['db']->fetchRow($res))

  25. {

  26. $arr[$row['rank_id']] = array(

  27. 'rank_name' => htmlspecialchars($row['rank_name']),

  28. 'price'=> price_format($row['price']));

  29. }

  30. return $arr;

  31. }

  32. }
复制代码
是否应改为
  1. /**

  2. * 获得指定商品的各会员等级对应的价格

  3. *

  4. * @accesspublic

  5. * @paraminteger$goods_id

  6. * @returnarray

  7. */

  8. function get_user_rank_prices_bast()

  9. {

  10. $sqlg="SELECT goods_id, shop_price FROM". $GLOBALS['ecs']->table('goods'). "ORDER BY goods_id DESC";

  11. $resg = $GLOBALS['db']->query($sqlg);



  12. while ($row = $GLOBALS['db']->fetchRow($resg))

  13. {



  14. $shop_price = $row['shop_price'];

  15. $goods_id= $row['goods_id'];



  16. //echo$shop_price."<br>";



  17. $sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $shop_price/ 100) AS price, r.rank_name, r.discount " .

  18. 'FROM ' . $GLOBALS['ecs']->table('user_rank') . ' AS r ' .

  19. 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp ".

  20. "ON mp.goods_id = '$goods_id' AND mp.user_rank = r.rank_id " .

  21. "WHERE r.show_price = 1 OR r.rank_id = '$_SESSION[user_rank]'";

  22. $res = $GLOBALS['db']->query($sql);

  23. $arr = array();

  24. while ($row = $GLOBALS['db']->fetchRow($res))

  25. {

  26. $arr[$row['rank_id']] = array(

  27. 'rank_name' => htmlspecialchars($row['rank_name']),

  28. 'price'=> price_format($row['price']));

  29. }



  30. }
  31. return $arr;
  32. }
复制代码
没有仔细看代码 也没测试。 只是感觉你 返回的数组位置错了。 在循环里面返回数组。 那只能得到第一个商品的 价格了 。。