papaface Posted February 23, 2007 Share Posted February 23, 2007 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? Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted February 23, 2007 Share Posted February 23, 2007 $selectposts = mysql_query("select posts_name,posts_content from posts where shoutboxes_unique_id='{$_id}' order by submitted_date LIMIT $_start, $_limit"); Remove the 'desc' monk.e.boy Quote Link to comment Share on other sites More sharing options...
papaface Posted February 23, 2007 Author Share Posted February 23, 2007 That doesnt work. It simply makes the results come out in ascending order, thats not what I need. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 Once you get the values, put them in an array and iterate through it backwards instead of forewards. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 23, 2007 Author Share Posted February 23, 2007 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++; } } } Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 Put the results of your mysql_fetch_array() into another array, instead of immediately printing them. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 23, 2007 Author Share Posted February 23, 2007 I tried: $reverse = mysql_fetch_array($selectposts); $i = 0; while (list($post_name,$post_content) = arsort($reverse)) but that doesnt work. Im so confused as to how I would do this. Quote Link to comment Share on other sites More sharing options...
artacus Posted February 23, 2007 Share Posted February 23, 2007 This is too easy: while ($row = mysql_fetch_assoc($result)) { $display = "<tr><td>$row[stuff]...snip...</tr>\n$display"; } Quote Link to comment Share on other sites More sharing options...
papaface Posted February 23, 2007 Author Share Posted February 23, 2007 That isnt what I want Quote Link to comment Share on other sites More sharing options...
papaface Posted February 23, 2007 Author Share Posted February 23, 2007 Can anyone please show me what I would need to do. It would be appreciated. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 23, 2007 Author Share Posted February 23, 2007 You can see what I mean with this page that I am coding: http://papaface.com/shoutbox/testing/test.html You can see that the latest message is at the top, when I want it at the bottom. However if I change the order by using asc in the SQL it will show the latest message on the last page (when enough messages are shouted). Quote Link to comment Share on other sites More sharing options...
artacus Posted February 23, 2007 Share Posted February 23, 2007 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 Quote Link to comment Share on other sites More sharing options...
papaface Posted February 23, 2007 Author Share Posted February 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
artacus Posted February 23, 2007 Share Posted February 23, 2007 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 ?> ... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.