-1

When I executed this code,

while($row = mysql_fetch_array($res))

there was an error of the following plan:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in String of treatment:while($row = mysql_fetch_array($res))

A J
  • 3,970
  • 14
  • 38
  • 53
ErR
  • 1
  • 1
  • 1
    English please.. and please provide your code already tried – Rendi Wahyudi Muliawan Mar 15 '18 at 07:42
  • There was an error of the following plan: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in String of treatment:while($row = mysql_fetch_array($res)) – ErR Mar 15 '18 at 07:56
  • show your all code, not just while, edit your post, and mysql is also deprecated, please use PDO or mysqli, you can read [here](http://php.net/manual/en/mysqli-result.fetch-array.php) – Rendi Wahyudi Muliawan Mar 15 '18 at 08:05
  • These extensions are already in use. PCP version 5.6.33. Piece of query: $query = 'SELECT Title,Key1,Key2,Key3,Key4,Key5,Key6,ID,Ans FROM `ucp_tests` ORDER BY RAND() LIMIT 10'; $res = mysql_query($query); $i = 0; while($row = mysql_fetch_array($res)) { How to present it for new extensions? – ErR Mar 15 '18 at 08:28

2 Answers2

1

$res should be an resource , for example

$res = mysql_query("SELECT * FROM table;");

after that only use mysql_fetch_array. Just for information This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

godot
  • 3,422
  • 6
  • 25
  • 42
Mahesh K S
  • 719
  • 1
  • 7
  • 15
1

Would be better to use mysqli_query instead of mysql_query. Read this answer and this PHP documentation about differences between them. So I advice you to use mysqli:

$result = mysqli_query($connection, 'SELECT id, name FROM some_table');

if($result){
     while($row = mysqli_fetch_assoc($result)){
           //extract values from row
           $id = $row['id'];
           $name = $row['name'];
     }
 }
godot
  • 3,422
  • 6
  • 25
  • 42