tags:

views:

45

answers:

6

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.

+4  A: 

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
+2  A: 

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
A: 

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

kevinmajor1
A: 

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.

middaparka
A: 
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  A: 

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)){
    }
}
clownbaby