Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql_query inside for loop gives mysql_fetch_assoc related error/warning
    text
    copied!<p>Im trying to get the id's of the questions that are answered or asked by particular user and than im trying to use those id's and get questions where id is different from the id's retrieved from the first query.While trying to achieve this im getting an mysql_fetch_assoc() related error/warning and as a result my program crashes.</p> <p>Following is the code from my DB_Functions.php file where im executing queries on database.</p> <pre><code>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&lt;sizeof($data); $i++){ $result2 = mysql_query("SELECT * FROM answers EXCEPT WHERE question_id='$data[i]'") or die(mysql_error()); return ($result2); } }else{ return false;} } </code></pre> <p>Following the code located in index.php where im trying to receive the result from DB_Functions.php</p> <pre><code>if($tag == 'getQuestions'){ $username = $_POST['username']; $getAllQuestions = $db-&gt;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); } </code></pre> <p>Below is the logcat message:</p> <pre><code>06-26 21:08:13.920: D/JSON(478): &lt;b&gt;Warning&lt;/b&gt;: mysql_fetch_assoc() expects parameter 1 to be resource, null given in &lt;b&gt;C:\xampp\htdocs\android_php_1\index.php&lt;/b&gt; on line &lt;b&gt;178&lt;/b&gt;&lt;br /&gt; </code></pre> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload