user2808698
user2808698

Reputation: 21

Order by id doesn't work

I have a trouble with order by in my mysql query. Without " WHERE adder='$followuser' " is query working fine.But with WHERE is ORDER BY not working. Can you help me please? :) Here's my code:

$time=time();
$checkfollowing=mysql_query("SELECT * FROM `follow` WHERE `follower`='$session'") or die(mysql_error()); /* Check if is user following somebody */

if(mysql_num_rows($checkfollowing) == FALSE){ /* He's following no one */
    echo "You follow noone";
    die();
}elseif(mysql_num_rows($checkfollowing) == TRUE){ /* He's following somebody */
    while($row11=mysql_fetch_array($checkfollowing)){
$followuser=$row11['get_follow'];

$fcontent=mysql_query("SELECT * FROM `followcontent` WHERE `adder`='$followuser' ORDER BY id DESC") or die (mysql_error()); /* Follow content */

while($row=mysql_fetch_assoc($fcontent)){
    $id=$row['id'];
    $photourl=$row['photourl'];
    $adder=$row['adder'];



    echo "<hr class='style'><br><div id='newadder'>".$adder."</div><a href='photo/?id=".$id."'><img src='".$photourl."' class='newfolimg'></a>";


}

} }

Thank you a lot :))

Upvotes: 2

Views: 343

Answers (2)

Mihai
Mihai

Reputation: 26784

Probably WHERE clause limits the result to one row,that`s why is "not working".

Upvotes: 0

John Woo
John Woo

Reputation: 263713

if the data type of your id is string then it will be sorted in lexicographical order. Try this trick,

ORDER BY id * 1 ASC

MySQL will implicitly convert the column into a number. If it happens that the value starts with a letter, the corresponding value will be 0.

Upvotes: 4

Related Questions