Alanp Posted April 9, 2014 Share Posted April 9, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/287636-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/ Share on other sites More sharing options...
B_CooperA Posted April 9, 2014 Share Posted April 9, 2014 (edited) 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 April 9, 2014 by B_CooperA Quote Link to comment https://forums.phpfreaks.com/topic/287636-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1475502 Share on other sites More sharing options...
gristoi Posted April 9, 2014 Share Posted April 9, 2014 do $answer = mysql_query( $getanswer, $con ) or die("MySQL ERROR: ".mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/287636-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1475503 Share on other sites More sharing options...
Jacques1 Posted April 9, 2014 Share Posted April 9, 2014 do $answer = mysql_query( $getanswer, $con ) or die("MySQL ERROR: ".mysql_error()); So that the whole world sees your MySQL issues and all the sensitive information associated with them? Internal error messages go into the log file, never on the user's screen. What you want is trigger_error(). Quote Link to comment https://forums.phpfreaks.com/topic/287636-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1475504 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.