Jump to content

Sorting Data when it echos


Pi_Mastuh

Recommended Posts

I'm trying to make my messageboard replies sort with the newest post at the bottom. How would I do that?

 

/////////////////////////////////////////////
// R E P L I E S
/////////////////////////////////////////////

// look for howmany rows have this replyToID
////////////////////////////////////////////////////

include ("secure/config.php");

///////////////////////////////////////////////////////////
$sql_repliessearch = "SELECT chibishopboard.messageID, chibishopboard.message, chibishopboard.replyToID, chibishopboard.title, chibishopboard.preuserID, chibishopboard.preuserName 
				  FROM chibishopboard
				  WHERE chibishopboard.replyToID='".$HTTP_GET_VARS['messageID']."'";

$result_sql_repliessearch = mysql_query($sql_repliessearch, $connection);
$numReplies = mysql_numrows($result_sql_repliessearch);

for($i=0; $i<$numReplies; $i++)
{
$messageID = mysql_result($result_sql_repliessearch,$i,"messageID");
$message = mysql_result($result_sql_repliessearch,$i,"message");
$currentpreuserID = mysql_result($result_sql_repliessearch,$i,"preuserID");

// get username
////////////////////////////////////////	
include ("secure/config.php");
///////////////////////////////////////////////////	
$sql_preusersearch = "SELECT chibifriends.preuserID, chibifriends.preuserName FROM chibifriends WHERE chibifriends.preuserID='".$currentpreuserID."'";
$currentpreuserName = mysql_result(mysql_query($sql_preusersearch, $connection), 0, "preuserName");

$sql = "SELECT * from chibifriends where preuserName ='$currentpreuserName'";
$result = mysql_query($sql, $connection);
$numShop = mysql_num_rows($result);
$query_data =mysql_fetch_array($result);
$currentAvvie = $query_data['avvie'];
$currentGender = $query_data['gender'];
$currentSiggy = $query_data['siggy'];

// find profileID for linking
// mike $sql_profilesearch = "SELECT profiles.preuserID, profiles.profileID FROM profiles WHERE profiles.preuserID='".$currentpreuserID."'";
// mike $profileID = @mysql_result(mysql_query($sql_profilesearch, $connection), 0, "profileID");
	$getsmileys = mysql_query("SELECT * from smileys");
while($rgsmileys = mysql_fetch_array($getsmileys)) 
{ 
extract($rgsmileys); 
$message = str_replace("$smiley_before", "<img src='$smiley_after'>", $message);
}
echo '<tr>
    <td width="*" bordercolor="#FF9900" bgcolor="#3366FF">
    <p align="center"><font color="#FFFFFF">Reply by: '.$currentpreuserName.'<br>'.$currentGender.'<br><br><img src='.$currentAvvie.'></font></td>
    <td width="*">'.$message.''; if (isset($currentSiggy)) { echo '<br><hr>'.$currentSiggy.'</td></tr>'; } else { echo '</td></tr>'; }
}

?>

Link to comment
Share on other sites

Add ORDER BY to the end of the SQL query that you want to sort.

 

Glancing over your code, it looks like this is probably where you want it:

$sql_repliessearch = "SELECT chibishopboard.messageID, chibishopboard.message, chibishopboard.replyToID, chibishopboard.title, chibishopboard.preuserID, chibishopboard.preuserName

  FROM chibishopboard

  WHERE chibishopboard.replyToID='".$HTTP_GET_VARS['messageID']."' ORDER BY chibishopboard.replyToID DESC";

Link to comment
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.