Jump to content

Mixing of GROUP columns??


Jessica

Recommended Posts

Could someone help me fix this:
[code]$get_items = "SELECT count(*) AS wood_count, unique_id FROM items WHERE owner = '$cookie_userid' AND location = 'inventory' AND item_id = 22";
if ($db_result = $db_conn->Execute($get_items)) {
    if ($db_result->RecordCount()) {
        while (!$db_result->EOF) {
            $wood_ids[] = $db_result->fields['unique_id'];
        }
        $wood_count = $db_result->fields['wood_count'];
    }
    $db_result->Close();
} else
    die('SQL Error #'.$db_conn->ErrorNo().': '.$db_conn->ErrorMsg());
[/code]

It gives the error
SQL Error #1140: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/5355-mixing-of-group-columns/
Share on other sites

I can't be much more informative than the error you already got. COUNT(*) is a group function, it operates on lots of rows. You can't mix group functions and columns for which you want per-row detail.

You are just trying to get a row count of your result, but that's why there is a mysql_num_rows() function (->RecordCount() with your database wrapper). Use that instead.

[code]$get_items = "SELECT unique_id FROM items WHERE owner = '$cookie_userid' AND location = 'inventory' AND item_id = 22";
if ($db_result = $db_conn->Execute($get_items)) {
    if ($db_result->RecordCount()) {
        while (!$db_result->EOF) {
            $wood_ids[] = $db_result->fields['unique_id'];
        }
        $wood_count = $db_result->RecordCount();
    }
    $db_result->Close();
} else
    die('SQL Error #'.$db_conn->ErrorNo().': '.$db_conn->ErrorMsg());[/code]
Link to comment
https://forums.phpfreaks.com/topic/5355-mixing-of-group-columns/#findComment-19075
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.