我有以下内容:
SELECT q25, COUNT( q25 ) AS count, AVG (q1) AS q1
FROM tresults WHERE id = 'Yes' AND date = 'MARCH2010' AND q25 = '1'
GROUP BY q25
目前,查询返回MySQL returned an empty result set (i.e. zero rows).
这是正确的 - 是否可以让它返回NULL
?
或
有没有办法在PHP事件之后处理这个问题,例如:
$resultprev = mysql_query($queryprev);
if($resultprev == ''){
// do something
}
答案 0 :(得分:3)
$resultprev = mysql_query($queryprev);
$num_rows = mysql_num_rows($resultprev);
if($num_rows == 0){
// 0 results !
}
或者你可以结合一个空行:
SELECT q25, COUNT( q25 ) AS count, AVG (q1) AS q1
FROM tresults WHERE id = 'Yes' AND date = 'MARCH2010' AND q25 = '1'
GROUP BY q25
UNION
SELECT null, null as count, null as q1
答案 1 :(得分:2)
试试这个
if(mysql_affected_rows($res)) {
//your stuff
}
或在sql中
SELECT (
SELECT q25, COUNT( q25 ) AS count, AVG (q1) AS q1
FROM tresults WHERE id = 'Yes' AND date = 'MARCH2010' AND q25 = '1'
GROUP BY q25
UNION
SELECT null, null, null
) AS x
LIMIT 1