m4x3vo Posted June 10, 2009 Share Posted June 10, 2009 <?php for ($counter = 1; $counter <= 139; $counter++) { $query = "SELECT * FROM user_ach WHERE user_id = $cookie AND ach_id = $counter"; $result1 = mysql_query($query); $res = mysql_fetch_assoc($result1); $ach_id = $res['ach_id']; if($ach_id != null) { $query2 = "SELECT * FROM ach WHERE id = $ach_id"; $result2 = mysql_query($query2); $res = mysql_fetch_assoc($result2); echo "<tr><td><img src='$res[image]'></img><br>$res[name]</td><td>$res[method]</td><td>$res[points]</td><td>$res[cat]</td><td>$res[status]</td></tr>"; echo "<br>"; } } ?> I have a loop like this, how can I use an ORDER BY to sort the results in the table.. Quote Link to comment https://forums.phpfreaks.com/topic/161605-order-by-in-a-loop/ Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 How do you want to sort? Quote Link to comment https://forums.phpfreaks.com/topic/161605-order-by-in-a-loop/#findComment-852829 Share on other sites More sharing options...
xtopolis Posted June 10, 2009 Share Posted June 10, 2009 Pretty much a double post: http://www.phpfreaks.com/forums/index.php/topic,255944.0.html Quote Link to comment https://forums.phpfreaks.com/topic/161605-order-by-in-a-loop/#findComment-852848 Share on other sites More sharing options...
m4x3vo Posted June 10, 2009 Author Share Posted June 10, 2009 No it isnt, its the same code but a different question.. Anyone I want to sort by the cat column. Quote Link to comment https://forums.phpfreaks.com/topic/161605-order-by-in-a-loop/#findComment-853219 Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 Anyone I want to sort by the cat column. First off, why are you using a counter? Just put an extra condition that takes care of this. Second, why can't you just sort by adding ORDER BY cat to your query? $query = "SELECT * FROM user_ach WHERE user_id = $cookie AND ach_id > 0 and ach_id NOTE - You will have to iterate through a while loop instead of the for loop. Quote Link to comment https://forums.phpfreaks.com/topic/161605-order-by-in-a-loop/#findComment-853231 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.