2012-04-12 5 views
-1

와 MySQL의 쿼리 나는이출력 PHP

$의 SQL과 같은 쿼리 = "SUM을 (CASE SELECT 때 jr_softwarecheck LIKE \ '% 소니 \'AND jr_othersoftware LIKE \ '% 소니 % \ 'THEN 2 ELSE 1 END) as totalcount from jos_jreviews_content 어디서나 jr_softwarecheck'% sony % \ '또는 jr_othersoftware LIKE \'% sony % \ ' ";

결과를 HTML 페이지로 출력하고 싶습니다. Joomla 기반 사이트를 실행합니다. 어떻게하면됩니까? 미안하지만 저는 PHP에 익숙하지 않아 배우고 있습니다. HTML 페이지 (프론트 엔드)에서

예상 결과, 예 :

SONY 제품 : 모든 사전에 105 개

감사합니다! 귀하의 경우에는

+0

좋은 신,이 같은 SQL 쿼리를 수행하지 않았 으면! –

답변

0
$result = mysql_query($sql) or die (mysql_error()); 
while($row = mysql_fetch_assoc($result)){ 
    //do something 
} 
1

, 다음과 같이 사용 :

$sql = "SELECT SUM(CASE WHEN jr_softwarecheck LIKE \'%sony\' AND jr_othersoftware LIKE \'%sony%\' THEN 2 ELSE 1 END) AS totalcount FROM jos_jreviews_content WHERE jr_softwarecheck LIKE \'%sony%\' OR jr_othersoftware LIKE \'%sony%\'"; 
    $res = mysql_query($sql); // This will run the query on the connected datababse 
    if($row = mysql_fetch_array($res)){ // Since you are using just a SUM to count results, you don't need to loop 
     echo "Sony Products: ".$row['totalcount']; // $row['totalcount'] is the result of the totalcount from your MySQL query put into the $row variable 
    } 

을 나는이 : 당신을하는 데 도움이