0

am trying to fetch values from the database but i get an error message "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\pyrll\index.php on line 58". Can someone help me?

here is the code:
`

$result = mysql_query("SELECT * FROM project ORDER BY  projectid DESC ");

while($rowsres = mysql_fetch_array($result)) //line 58

echo "$rowsres[projectname]";

?>`
Jush
  • 193
  • 1
  • 3
  • 9

2 Answers2

0

Without the code you are using it's hard to say. But mostly this error occurs when the previous mysql_* function failed and it did not return a result. Instead try to use mysql_*(<blabla>) or die(mysql_error()) for verifying the function worked.

As a side note, try to refrain from mysql_* functions; they are in the depreciation process. Use mysqli_* or PDO.

Luceos
  • 6,629
  • 1
  • 35
  • 65
0

It's possible that:

  1. You don't have an active database connection

  2. The query result does not yield anything (ie the response is NULL) or

  3. There is a syntax error in your query

I would use a program like Toad (Windows) or Sequel Pro (Mac OS) or good ol' terminal to check that your query yields a result.

If you are using something like a sprintf() to assemble your query from variable, ensure that you are getting the proper string output with an echo.

mysql_connect("localhost", "mysql_user", "mysql_password") or

die("Could not connect: " . mysql_error());

mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

Check that the query string (SELECT id, name FROM mytable) works externally

eg. echo $query = sprintf("SELECT id, name FROM mytable WHERE id = %d",$var);

if echo $query yields something like:

[GOOD]: SELECT id, name FROM mytable WHERE id = 5

else

[BAD]: SELECT id, name FROM mytable WHERE id = 

If the outputs well, then the rest should work just fine. Unless of course you don't have access to a database.

while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("ID: %s Name: %s", $row[0], $row[1]);
}

mechimdi
  • 318
  • 4
  • 6