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
https://forums.phpfreaks.com/topic/36855-sorting-data-when-it-echos/
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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.