Jump to content

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given


Alanp

Recommended Posts

Hello! every one.

 

I have my php-mysql codes bellow which gives the error

"Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\jopasy_community_2.2\includes\view.php on line 28"

 

bellow are the codes

 

<?php
    include 'connection.php';
    $con = mysql_connect($host,$user,$pwd);
    $db = mysql_select_db($database);
    
    include 'create_tables.php';
    
    $sql = 'SELECT name, qntitle, question  FROM questions';
    
    $retval = mysql_query( $sql, $con );
    if(! $retval )
    {
      die('Could not get data: ' . mysql_error());
    }
    while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
    {
    $qnabout=$row['qntitle'];
    
        echo "<b>Question: </b>{$row['question']} <br>".
         "<b>Asked by : </b> {$row['name']} <br> ".
         "<b>Question about: </b> {$row['qntitle']} <br><br> ".
         
         "<b>Answers</b> <br><br> ".
        
        $getanswer = ("SELECT answerdby, answer FROM answers WHERE qntitle ='".$qnabout."';");
        $answer = mysql_query( $getanswer, $con );
        
        while($ans = mysql_fetch_array($answer, MYSQL_ASSOC)) // THIS IS THE LINE WITH ERROR
        {
         echo "Answer : {$ans['answer']} <br> ".
         "<b>Answered by : </b> {$ans['answerdby']} <br> ".
         "--------------------------------<br><br><br><hr>";
        }
        
    }
    mysql_close($con);

?>

 

I dont know how to solve it. i need help plz

Link to comment
Share on other sites

E: Propably SQL error, since the previous one is working

 

try this:

while($row = mysql_fetch_assoc($retval)) {
// do your stuff
}

Oh yeah, you shouldn't use mysql functions anymore. They're deprecated, use PDO or mysqli instead.

Edited by B_CooperA
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.