-1

我有这样的查询

$sql = "SELECT SUM(当 jr_softwarecheck LIKE \'%sony\' AND jr_othersoftware LIKE \'%sony%\' THEN 2 ELSE 1 END) 作为总数来自 jos_jreviews_content WHERE jr_softwarecheck LIKE \'%sony%\' OR jr_othersoftware LIKE \'%sony%\'";

我想在 HTML 页面中输出结果。我运行一个基于 Joomla 的网站。我怎样才能做到这一点?抱歉,我在 PHP 方面不太熟练,我正在学习。

HTML 页面(前端)中的预期结果,例如:

索尼产品:105

在此先感谢大家!

4

2 回答 2

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
    }

我希望这可以帮助你 :)

于 2012-04-13T08:13:37.380 回答
0
$result = mysql_query($sql) or die (mysql_error());
while($row = mysql_fetch_assoc($result)){
    //do something
}
于 2012-04-12T22:25:58.710 回答