我有一个这样的查询
$sql = "选择 SUM(当jr_softwarecheck像 '''%SONY''' 和 jr_othersoftware 像 '''%sony%''' 然后 2 个其他 1 结束)作为总数从 jos_jreviews_content jr_softwarecheck喜欢 '''%索尼%''' 或 jr_othersoftware 喜欢 '''%索尼%'''";
我想在 HTML 页面中输出结果。我经营着一个基于Joomla的网站。我该怎么做?对不起,我对PHP不是那么熟练,我正在学习。
HTML 页面(前端)中的预期结果,示例:
索尼产品: 105
提前感谢大家!
在您的情况下,请像这样使用它:
$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
}
我希望这对你有所帮助:)
$result = mysql_query($sql) or die (mysql_error());
while($row = mysql_fetch_assoc($result)){
//do something
}