1
我試圖得到特定用戶回答或要求的問題的id,而不是嘗試使用這些id的問題,並得到問題,其中id與從中檢索到的id不同第一個查詢。當試圖實現這個我得到一個mysql_fetch_assoc()相關的錯誤/警告,結果我的程序崩潰。mysql_query裏面for循環給出mysql_fetch_assoc相關的錯誤/警告
以下是我的DB_Functions.php文件中的代碼,其中im在數據庫上執行查詢。
public function getQuestions($username){
$result = mysql_query("SELECT question_id FROM answered WHERE asked_by = '$username' OR answered_by = '$username'");
if($result){
$data = array();
while($row = mysql_fetch_assoc($result)) {
$data[] = array(
$r=$row["question_id"]);}
for($i=0; $i<sizeof($data); $i++){
$result2 = mysql_query("SELECT * FROM answers EXCEPT WHERE question_id='$data[i]'") or die(mysql_error());
return ($result2);
}
}else{
return false;}
}
繼位於index.php文件的代碼中我嘗試從DB_Functions.php接收結果
if($tag == 'getQuestions'){
$username = $_POST['username'];
$getAllQuestions = $db->getQuestions($username);
$data = array();
while($row = mysql_fetch_assoc($getAllQuestions)) { //I'm getting ERROR on this line
$data[] = array(
$response["getAllQuestions"]["id"] = $row["id"],
$response["getAllQuestions"]["username"] = $row["username"],
$response["getAllQuestions"]["question_id"] = $row["question_id"],
$response["getAllQuestions"]["question"] = $row["question"],
$response["getAllQuestions"]["tag1"] = $row["tag1"],
$response["getAllQuestions"]["tag2"] = $row["tag2"],
$response["getAllQuestions"]["tag3"] = $row["tag3"],
$response["getAllQuestions"]["question_time"] = $row["question_time"]);}
echo json_encode($data);
}
下面是logcat的消息:
06-26 21:08:13.920: D/JSON(478): <b>Warning</b>: mysql_fetch_assoc() expects parameter 1 to be resource, null given in <b>C:\xampp\htdocs\android_php_1\index.php</b> on line <b>178</b><br />
感謝
可能的重複[Warning:mysql_fetch_ *期望參數1是資源,布爾給定錯誤](http://stackoverflow.com/questions/11674312/warning-mysql-fetch-expects-parameter-1-tobe -resource布爾給出的誤差) – j0k