麻烦高手帮看一下,怎么foreach没能循环,谢谢!

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


  1. elseif ($action == 'mybuy')
  2. {
  3. include_once(ROOT_PATH . 'includes/lib_clips.php');

  4. $page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;

  5. $record_count = $db->getOne("SELECT COUNT(*) FROM " .$ecs->table('order_info').
  6. " WHERE user_id='$user_id' ORDER BY order_id DESC");

  7. $pager = get_pager('user.php', array('act' => $action), $record_count, $page);
  8. $smarty->assign('pager', $pager);
  9. $smarty->assign('goods_buy', get_mybuy($user_id, $pager['size'], $pager['start']));
  10. $smarty->assign('url',$ecs->url());
  11. $lang_list = array(
  12. 'UTF8'=> $_LANG['charset']['utf8'],
  13. 'GB2312' => $_LANG['charset']['zh_cn'],
  14. 'BIG5'=> $_LANG['charset']['zh_tw'],
  15. );
  16. $smarty->assign('lang_list',$lang_list);
  17. $smarty->assign('user_id',$user_id);
  18. $smarty->display('user_clips.dwt');
  19. }
复制代码


  1. function get_mybuy($user_id, $num = 10, $start = 0)
  2. {

  3. $sql = 'SELECT c.user_id,c.order_sn, g.rec_id,c.order_id, g.goods_id, g.order_id, g.goods_name '.
  4. ' FROM ' . $GLOBALS['ecs']->table('order_info'). ' AS c '.
  5. " LEFT JOIN " . $GLOBALS['ecs']->table('order_goods'). " AS g ".
  6. "ON g.order_id = c.order_id ".
  7. " WHERE c.user_id = '$user_id' ";


  8. $res = $GLOBALS['db']->selectLimit($sql, $num, $start);

  9. $goods_buy = array();
  10. while ($row = $GLOBALS['db']->fetchRow($res))
  11. {
  12. $goods_buy[$row['goods_id']]['order_sn']= $row['order_sn'];
  13. }

  14. return $goods_buy;
  15. }
复制代码


  1. <!--{foreach from=$goods_buy item=goods}-->
  2. <tr>
  3. <td align="center" valign="middle" bgcolor="#ffffff">
  4. 订单号:{$goods.order_sn}</a>
  5. </td>
  6. </tr>
  7. <!--{/foreach} -->
复制代码


只能显示数据库的最后一条数据

回答:
=-= 虽不懂但觉厉

很简单的事情,在PHP页面拦截活着输出下数据,看是否有数据 然后才看模版显示

有数据,只能显示数据库的最后一条数据

while ($row = $GLOBALS['db']->fetch_array($res))

还是一样只输出一条数据,真是奇了怪