Jump to content

[SOLVED] Issue with Making a Message Board


947740

Recommended Posts

I am making a message board, but I am having trouble listing the entries in the order I want them.

 

Here is my current code to pull the info from the database:

 

<?php

 

include("includes\message_board.inc");

 

 

$cxn = mysqli_connect($host,$user,$password,$db);

 

$sq1 = "SELECT * FROM messages";

 

$result = mysqli_query($cxn,$sq1);

 

while($row = mysqli_fetch_row($result))

{

echo"<tr><td>$row[0]</td><td>$row[1]</td><td>$row[3] $row[2], $row[4]</td><td>$row[5]</td><td>$row[6]</td></tr>";

}

 

?>

 

Currently it lists the messages with the earliest on top, but I want the latest on top, seeing as I want the newest messages to be easily seen.

 

I tried some code like this in place of the previous while statement.:

 

for ($n=$affected;$n>0;$n--)

{

while($backwards_array[$n] = mysqli_fetch_assoc($result))

{

$test = $backwards_array[$n]['Message'];

 

 

}

 

 

}

 

  I have tried many different variations, especiall of the $test placement.  I believe the easy way to do this is to put each row element into an array and run through the array backwards, displaying the information in the correct order.  However, I have not been able to figure out how to set up the array correctly.  I would greatly appreciate any help you could give me with this. :-\

Link to comment
Share on other sites

You could have read everything into an array and then used the array_reverse() function, or you could have read everything into an array and used a for loop starting with the last item of the array and working backwards.

 

Much easier to get a database to sort though.

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.