-2

I keep getting Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in xx on line 6

error what is the problem with this code ? how can I fix it ?

$read = mysql_query("select * from detail");

while($wr = mysql_fetch_array($read)) {
echo $wr['Who'];
echo "<br />";
echo $wr['Time'];
echo "<br />";
echo $wr['What'];
}

edit; I made it like this still giving an error.

$db = new mysqli('localhost', 'root', '', 'panel');
$sql = "select * from detail";
$read = $db->query($sql);

while($wr = mysql_fetch_array($read)) {
echo $wr['Who'];
echo "<br />";
echo $wr['Time'];
echo "<br />";
echo $wr['What'];
}
Extelliqent
  • 1,760
  • 5
  • 32
  • 51
  • 1
    If you search for the exact error message, you get more than enough similar questions. For example: http://stackoverflow.com/questions/2973202/php-error-mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given – deceze Dec 28 '11 at 05:16
  • I did. everybody have different solutions to each problem. Mine must be so easy – Extelliqent Dec 28 '11 at 05:21
  • What does `var_dump($read)` give you right before the loop? – deceze Dec 28 '11 at 05:22
  • 1
    object(mysqli_result)[2] public 'current_field' => null public 'field_count' => null public 'lengths' => null public 'num_rows' => null public 'type' => null – Extelliqent Dec 28 '11 at 05:24

3 Answers3

3

You are mixing the MySQL and MySQLi extensions!
Use the appropriate functions of either, not both.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • Thanks for the clue I just added "i" to mysql now problem solved. I put while($wr = mysqli_fetch_array($read)) { instead of while($wr = mysql_fetch_array($read)) { – Extelliqent Dec 28 '11 at 05:32
1

You probably having problems with querying database since your query fails:

$read = mysql_query("select * from detail"); // $read is false

// You can try to discover the error.
$read = mysql_query("select * from detail") || die(mysql_error());
Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
0

Use this code:

$read = mysql_query("select * from detail");

while($wr = mysql_fetch_array($read,  MYSQL_ASSOC)) {
echo $wr['Who'];
echo "<br />";
echo $wr['Time'];
echo "<br />";
echo $wr['What'];
}

See for more information: mysql-fetch-array

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226