按ID分组不在php中分组

im having a bit of a problem with my php script that counts the id column entries that match a certain questionnaire id. The results seem to be quite antisocial and just dont want to group up for some reason....

        $sql30 = <<<SQL
    SELECT id, COUNT(id) 
    FROM `QuestionnaireAnswers`
    WHERE questionnaireID='$questionnaireID'
    GROUP BY id
    SQL;
    if(!$result30 = $db->query($sql30)){ die('There was an error running the query [' . $db->error . ']');}
    while($row30 = $result30->fetch_assoc()){
        if ($row30['COUNT(id)'] == '' OR $row30['COUNT(id)'] == '0'){$numberofresponses = '0';}
        else {$numberofresponses = $row30['COUNT(id)'];}    
    echo '<td>'.$numberofresponses.'</td>';
    }

If I use a sample questionnaireID of 1327809154 and run the following query in phpmyadmin :

SELECT id, COUNT( id ) 
FROM  `QuestionnaireAnswers` 
WHERE questionnaireID =  '1327809154'
GROUP BY id
LIMIT 0 , 30

I get the following results :

id  COUNT(id)
129 1
130 1
131 1
132 1
133 1
134 1
277 1
278 1
280 1
281 1
282 1
284 1
290 1
419 1
424 1
425 1
426 1

so.....it appears to be counting the results, but not grouping them to give me a total.........

EDIT,I have now changed it to :

        $sql30 = <<<SQL
    SELECT questionnaireID, COUNT(questionnaireID) 
    FROM `QuestionnaireAnswers`
    WHERE questionnaireID='$questionnaireID'
    GROUP BY questionnaireID
    SQL;
    if(!$result30 = $db->query($sql30)){ die('There was an error running the query [' . $db->error . ']');}
    while($row30 = $result30->fetch_assoc()){
        if ($row30['COUNT(questionnaireID)'] == '' OR $row30['COUNT(questionnaireID)'] == '0'){$numberofresponses = '0';}
        else {$numberofresponses = $row30['COUNT(questionnaireID)'];}   
    echo '<td>'.$numberofresponses.'</td>';
    }

This returns :

questionnaireID COUNT(questionnaireID)
 1327809154 17

this works in phpmyadmin, but some reason nothing is returned in my script, the table column where the count should be is blank.

Your IDs are all unique, so they cannot be grouped. Only equal values are grouped together and their count summed up.

You're query is simply getting all the ids and since each of them is unique, its displays the count as 1 for each of them, instead to get count of the number of responses just use

SELECT COUNT(id) FROM `QuestionnaireAnswers` 
WHERE questionnaireID =  '1327809154'

Ok, iv sorted it now, the reason it didnt work after the edit was because I didnt define questionnaireID in the while loop. $questionnaireID = $row['questionnaireID'];

This returns the number of different non-NULL values​​.

SELECT COUNT(DISTINCT `id`) 
FROM  `QuestionnaireAnswers` 
WHERE questionnaireID =  '1327809154'

You do not need GROUP BY, because you have only one questionnaireID.