2015-01-24 7 views
-1

Laravel v 4.2.0을 사용하여 데이터베이스 테이블에 저장된 데이터의 양을 표시하고 싶지만 count() 함수 사용에 문제가 있습니다. 여기 내 코드는 다음과 같습니다수를 선택하는 방법 laravel

$total = DB::select("select count(*) from rents left join operators on operators.code = rents.code where (operators.code is null) and rents.booking = 'N'");  
echo $total; 

메시지 오류 말 :

Syntax error or access violation 

누구든지 나를 도울 수 있습니까?

답변

0

이 시도 :

$total = DB::select(DB::raw("select count(*) as cnt from rents left join operators on operators.code = rents.code where (operators.code is null) and rents.booking = 'N'"));  
echo $total[0]->cnt; 

시도 디버깅 :

echo "<pre>"; 
print_r($total); 
echo "</pre>"; 
exit; 

참조, 즉 도움이된다면.

+0

실행할 수 없습니다. 여전히 오류 –

+0

동일한 오류가 발생합니까? –

+0

SQL 쿼리를 가져 오는 결과가 있습니까? –

관련 문제