MYSQL计算不同的单元格值

时间:2014-03-23 20:21:35

标签: php mysql

我试着用以下方法计算 - 包括'db_login';

    $sql = "(SELECT  * , COUNT(*)  FROM  `table1` 
    WHERE  `ADVERTISERCATEGORY` LIKE  '%something%'
    GROUP BY `MANUFACTURER` ORDER BY COUNT DESC )";
    $row = mysql_fetch_array($sql);
    $total = $row[0];
    echo "Total rows: " . $total;

但是我收到了以下错误消息 -

Warning: mysql_fetch_array() expects parameter 1 to be resource, 
string given in /home/content/43/10130843/html/fashion_test.php on line 169

我正在学习php / mysql因此我需要帮助。 感谢

1 个答案:

答案 0 :(得分:1)

你还没有打电话给mysql_query(),所以你还无法获取阵列......

$sql = "SELECT  * , COUNT(*)  FROM  `table1` 
WHERE  `ADVERTISERCATEGORY` LIKE  '%something%'
GROUP BY `MANUFACTURER` ORDER BY COUNT(*) DESC ";
$query = mysql_query($sql) or die(mysql_error()); // exit on error
$row = mysql_fetch_array($query);

注意: mysql_query() and the rest of the mysql_* library have been deprecated一段时间后,您应该在开发过程中转移到mysqli_*PDO的参数化查询相。