'장바구니 간소 데이터 가져오기' 관련 질문
본문
//장바구니 간소 데이터 가져오기
function get_boxcart_datas($is_cache=false)
{
global $g5;
$cart_id = get_session("ss_cart_id");
if( !$cart_id ){
return array();
}
static $cache = array();
if( $is_cache && !empty($cache) ){
return $cache;
}
$sql = " select * from {$g5['g5_shop_cart_table']} ";
$sql .= " where od_id = '".$cart_id."' group by it_id ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
$key = $row['it_id'];
$cache[$key] = $row;
}
return $cache;
}
//장바구니 간소 데이터 갯수 출력
function get_boxcart_datas_count()
{
$cart_datas = get_boxcart_datas(true);
return count($cart_datas);
}
-----------------------------------------------
$sql .= " where od_id = '".$cart_id."' group by it_id ";
$sql .= " where od_id = '".$cart_id."' ";
로 변경하여 동일상품을 여러번 카트에 담을 경우에도 카운트가 늘어나도록 하려 하였습니다.
그러나 group by it_id 를 제거 하였음에도 결과값이 동일하게 나오는 이유를 알고자 합니다.
도움 요청드립니다.
답변 2
$key = $row['it_id'];
$cache[$key] = $row;
위코드 때문입니다
다음처럼 수정하세요
$cache[] = $row;
echo print_r($sql); 로 각각의 값들을 비교해 보세요...
어떤 값들이 들어와 오는지....
group by it_id 로 묶었다면 it_id 값이 같은 것들이 하나로 묶여서 보여질 것입니다.