Jump to content

Mysql Retrieve order


papaface

Recommended Posts

Hello,

This is very difficult to explain. But I have a table and it has the following code:

$selectposts = mysql_query("select posts_name,posts_content from posts where shoutboxes_unique_id='{$_id}' order by submitted_date desc LIMIT $_start, $_limit");

 

This page has pagination on it. So I want to display the most recent post on the first page, however I want to display the most recent at the bottom of the first page.

Currently is DOES show the most recent post on the first page BUT it is at the top.

 

How can this be done?

Link to comment
Share on other sites

I dont understand how I would do that with this:

$selectposts = mysql_query("select posts_name,posts_content from posts where shoutboxes_unique_id='{$_id}' order by submitted_date desc LIMIT $_start, $_limit");

if	(mysql_num_rows($selectposts) == 0)
{
echo '<span class="shout_text">There are currently no posts to display.</span>';
}
else
{
$i = 0;
while	(list($post_name,$post_content) = mysql_fetch_array($selectposts))
	{
	if($i%2 == 0)
		{
		echo '<div class="shout_text">' . $post_name . ': ' . $post_content . "</div>";
		$i++;
		}
	else
		{
		echo '<div class="shout_text2">' . $post_name . ': ' . $post_content . "</div>";
		$i++;
		}

	}

}

Link to comment
Share on other sites

That isnt what I want. Can anyone please show me what I would need to do. It would be appreciated.

 

 

It is what you want. Jesirose and I both gave you a workable solution. Now stop sniveling, and pay attention.

Run your query in normal order from highest to lowest so you'll get back the last 50 responses. (1 -> 50)

As you process each row, write your current row BEFORE your previous rows. So what you'll have is:

row 50

row 49

...

row 2

row 1

Link to comment
Share on other sites

Oh honestly, I wasnt sniveling, I was just asking for help.

What you and Jesirose have provided may be useful in an ideal situation but what you are proposing cant be done with my code.

If you actually took a second to look at it, you will see that my results get divided in two.

Link to comment
Share on other sites

LOL. There's two options here, one is that you are very crafty and are playing us to get the code written for you. I'm going to assume that's not the case.

 

$result = mysql_query($query);

if(mysql_num_rows($result) == 0) {
   $disp = ''<span class="shout_text">There are currently no posts to display.</span>';
} else {
   while($row = mysql_fetch_assoc($result)) {
      $class = ($i++ % 2) ? 'shout_text' : 'shout_text2';
      $disp = "<div class='$class'>$row[post_name] : $row[post_content]</div>\n" . $disp; //keep adding to the top here
   }
}
echo '<div class="shout_text">' . $post_name . ': ' . $post_content . "</div>";
?>
...html stuff
<body>
<?=$disp ?>
...

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.