Jump to content

Recommended Posts

<?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..

Link to comment
https://forums.phpfreaks.com/topic/161605-order-by-in-a-loop/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/161605-order-by-in-a-loop/#findComment-853231
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.