-1

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

When i try so sort my output to DESC, i get this error:

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

This is my line:

$queryForWall = mysql_query("SELECT * FROM users_wall WHERE uID = '$showU[id]' DESC");
while($displayWall = mysql_fetch_array($queryForWall)){

As you can see i added DESC there, but I keep receiving error.

Community
  • 1
  • 1
Karem
  • 17,101
  • 71
  • 169
  • 273
  • 1
    First of all you should use ORDER BY yourColumn DESC – Centurion Aug 12 '10 at 20:47
  • 1
    Also, don't use a string for an array key, use `$showU['id']`. And, you're lacking concatenators; you want that to probably read `SELECT * FROM users_wall WHERE uID = '.$showU['id'].' ORDER BY users_wall DESC` – Andrew Aug 12 '10 at 20:49

6 Answers6

4

DESC by itself isn't valid.

You need

ORDER BY <some column or expression> DESC

More generally, you should devise some way to tell when a SQL query is wrong.

Perhaps something like:

<?PHP
$result = mysql_query('<some sql query>');
if (! $result){
     $error = mysql_error();
     //do something with $error, like logging it, using it with trigger_error, etc
}
while($row = mysql_fetch_array($result)){
    // process results normally
}
timdev
  • 60,131
  • 6
  • 78
  • 90
2

You need an ORDER BY.

SELECT * FROM users_wall WHERE uID = '$showU[id]' ORDER BY uID DESC

The query is causing an error which means $queryForWall == false. That's why the php warning is saying you're passing a boolean value as your argument (because you are).

Jage
  • 7,920
  • 3
  • 31
  • 30
1

The answers posted already are correct. However, I wanted to add one more thing. You got your original error message because your SQL was bad, and mysql_query was failing. If you check the PHP documentation, you'll see that mysql_query returns FALSE on error.

You should always check the result of a SQL query before trying to loop over your result set, like so:

$queryForWall = mysql_query("SELECT * FROM users_wall WHERE uID = '$showU[id]' ORDER BY uID DESC");
if ($queryForWall) {
    while($displayWall = mysql_fetch_array($queryForWall)){
    }
}
danjarvis
  • 9,680
  • 3
  • 21
  • 21
0

The way you're attempting to use DESC suggests you're attempting to order the results of your SELECT query. To do this, you need to use ORDER BY. See: http://dev.mysql.com/doc/refman/5.4/en/select.html

Major Productions
  • 5,716
  • 11
  • 66
  • 144
0

If you're attempting to order the results you need to use the ORDER BY clause.

For example:

SELECT * FROM users_wall WHERE ... ORDER BY date_added DESC

Check out the full SELECT syntax for more information.

John Parker
  • 53,316
  • 11
  • 128
  • 128
0
SELECT * FROM users_wall WHERE uID = '$showU[id]' ORDER BY uID DESC

You need to specify which column you're ordering by descending.

marramgrass
  • 1,411
  • 14
  • 17