2016-12-27 4 views
1

Codeigniter를 처음 사용했습니다. 내 쿼리가 작동하지 않는 것 같습니다 문제가 있습니다. 내 포맷 때문인가요?CodeIgniter SQL 다른 테이블에서 데이터를 가져 오는 올바른 형식

모델

$this->db->select('*'); 
    $this->db->from(' 
    store_products, 
    products, 
    category, 
    subcategory, 
    store, 
    store_products_category'); 
    $this->db->where('store_products_category.store_id', $marketid); 
    $this->db->where('store_products_category.subcategory_id', 'subcategory.subcategory_id'); 
    $this->db->where('subcategory.category_id', 'category.category_id'); 
    $this->db->where('store_products_category.storeprod_id', 'store_products.storeprod_id'); 
    $this->db->where('store_products.prod_id', 'products.prod_id'); 
    $this->db->where('store_products_category.store_id', 'store.store_id'); 
    $query = $this->db->get(); 
    $result = $query->row(); 

    return $result; 

컨트롤러

if($marketinfo = $this->MarketModel->getInfobyID($marketid)){ 
    $data['marketinfolist'] = $marketinfo; 
    $this->load->view('layouts/header', $data); 
    $this->load->view('clickbasket',$data); 
    $this->load->view('navigation/mainfooter'); 
    $this->load->view('layouts/footer'); 
} 

모델에서 아무것도 반환하지 수있는 것 같다. 필자는 이미 phpMyAdmin에서 직접 쿼리를 시도하고 완벽하게 작동합니다.

답변

2

는이처럼 ... 적절한 결과를 얻기 위해 테이블에 가입해야 ..

모형 :

$query = $this->db->select('*') 
       ->from('store_products') 
       ->join('products', 'store_products.prod_id = products.prod_id') 
       ->join('store_products_category', 'store_products_category.storeprod_id = store_products.storeprod_id') 
       ->join('subcategory', 'store_products_category.subcategory_id = subcategory.subcategory_id'); 
       ->join('category', 'subcategory.category_id = category.category_id') 
       ->join('store', 'store_products_category.store_id = store.store_id') 
       ->where('store_products_category.store_id', $marketid) 
       ->get(); 
$result = $query->row(); 
return $result; 

그리고 컨트롤러에서

..

function getMarketInfo($marketid) 
    { 
    if(!empty($marketid)){ 
    $marketinfo = $this->MarketModel->getInfobyID($marketid); 
    $data['marketinfolist'] = $marketinfo; 
    $this->load->view('layouts/header', $data); 
    $this->load->view('clickbasket',$data); 
    $this->load->view('navigation/mainfooter'); 
    $this->load->view('layouts/footer'); 
    } 
    } 
+0

당신을 감사 지금은 잘 작동합니다 :) $ query-> row() 부분을 조정해야했습니다. –

1

질문을 올바르게 이해하고 있다면 부적절한 조인이 적용되고 코드 점화기가 올바른 쿼리를 생성 할 수 없어 발생합니다. 복사하여 테스트하기 위해 MySQL의에서이를 실행할 수있는 다음 문을 수행하여 브라우저에 쿼리를 인쇄 할 수 있습니다, 또한

$query = $this->db->select('*') 
       ->from('store_products') 
       ->join('products', 'store_products.prod_id = products.prod_id') 
       ->join('store_products_category', 'store_products_category.storeprod_id = store_products.storeprod_id') 
       ->join('subcategory', 'store_products_category.subcategory_id = subcategory.subcategory_id'); 
       ->join('category', 'subcategory.category_id = category.category_id') 
       ->join('store', 'store_products_category.store_id = store.store_id') 
       ->where('store_products_category.store_id', $marketid) 
       ->get(); 
$result = $query->row(); 

과 :

echo $this->db->last_query(); 

그것은 현재에 의해 실행 된 가장 최근의 쿼리를 인쇄이 시도 모델.

관련 문제