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