目前我使用此代碼統計調查的答覆從MySQL數據庫來算調查答覆:一個更合適的方法
$VERYHAPPY = mysql_query("SELECT * FROM answers, complete WHERE (answers.uniqueID = complete.uniqueID) AND (complete.timestamp) IS NOT NULL AND (answers.surveyID='$surveyID') AND QID = '$QID' AND response = 'VERY HAPPY' ");
$HAPPY = mysql_query("SELECT * FROM answers, complete WHERE (answers.uniqueID = complete.uniqueID) AND (complete.timestamp) IS NOT NULL AND (answers.surveyID='$surveyID') AND QID = '$QID' AND response = 'HAPPY' ");
$DONTKNOW = mysql_query("SELECT * FROM answers, complete WHERE (answers.uniqueID = complete.uniqueID) AND (complete.timestamp) IS NOT NULL AND (answers.surveyID='$surveyID') AND QID = '$QID' AND response = 'DONT KNOW' ");
$UNHAPPY = mysql_query("SELECT * FROM answers, complete WHERE (answers.uniqueID = complete.uniqueID) AND (complete.timestamp) IS NOT NULL AND (answers.surveyID='$surveyID') AND QID = '$QID' AND response = 'UNHAPPY' ");
$VERYUNHAPPY = mysql_query("SELECT * FROM answers, complete WHERE (answers.uniqueID = complete.uniqueID) AND (complete.timestamp) IS NOT NULL AND (answers.surveyID='$surveyID') AND QID = '$QID' AND response = 'VERY UNHAPPY' ");
$VERYHAPPYcount = mysql_num_rows($VERYHAPPY);
$HAPPYcount = mysql_num_rows($HAPPY);
$DONTKNOWcount = mysql_num_rows($DONTKNOW);
$UNHAPPYcount = mysql_num_rows($UNHAPPY);
$VERYUNHAPPYcount = mysql_num_rows($VERYUNHAPPY);
echo "VERY HAPPY = $VERYHAPPYcount</br>HAPPY = $HAPPYcount</br>DON'T KNOW = $DONTKNOWcount</br>UNHAPPY = $UNHAPPYcount</br>VERY UNHAPPY = $VERYUNHAPPYcount";
,你可以看到 - 這是真的亂了!任何更好的方式來做到這一點?我試過COUNT和GROUP BY,但無法讓他們工作。由於
作爲一個方面說明,我d建議查看PHP中的PDO功能。一個小的學習曲線(與現在的曲線大致相同)和靈活性大大增加。 http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/ – Ben
*你回來了什麼信息?你是否在你的結果對象上嘗試了'var_dump'或'printr'來查看你回來的東西? – Ben