Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to reverse an array

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 29-07-2010
Member
 
Join Date: Mar 2010
Posts: 360
How to reverse an array
  

Hello,
This is my problem, I made a shoutbox. But when I retrieve messages if I put an ORDER CSA, I only get the first posts. And if I put an ORDER ESCR, it gives me the good, but the oldest is at the top of the list. In other words how can I reverse the array, because this will solve my problem. Any help is appreciated. Thank you.

Reply With Quote
  #2  
Old 29-07-2010
Member
 
Join Date: Dec 2009
Posts: 202
Re: How to reverse an array

I can only answer only one part of your question. Can you show us your queries complete? It should look like this:
SQL - Select
Code:
SELECT * FROM shoutbox ORDER BY id
I think this should work for you.
Reply With Quote
  #3  
Old 29-07-2010
Member
 
Join Date: Dec 2009
Posts: 213
Re: How to reverse an array

Hello,
Check out the following code, this may help you

Code:
<? Php
/ / ...
$ rshts = mysql_query('SELECT * FROM shoutbox ORDER BY id DESC LIMIT 0, 8')
	
	/ / Can we make a loop to display all results
	while ( $ shts = mysql_fetch_array($ rshts) )
	(
	$ msg = bbcode(htmlspecialchars($ shts['message']));
	$ pse = htmlspecialchars($ shts['username']);
	$ hre = date('H \ hi', $ shts[' timestamp ']);
	$ dt = date_naturelle($ shts['timestamp'])
	
	echo '
	<tr>
		<td> '.$ pse.'</ td>
		<td> <a title = "Message posted on '.$ dt.'">'.$ hre.'</ a> </ td>
		<td style="width: 70%;"> ".$ msg.'</ td>
	</ tr>
	
	';
	)
Reply With Quote
  #4  
Old 29-07-2010
Member
 
Join Date: Mar 2010
Posts: 162
Re: How to reverse an array

This is a more practical code, just try it

Code:
<? Php
   / / ON LINE HAS A MySQL

   $ sq = mysql_query("SELECT * FROM shoutbox");
   $ ness = mysql_num_rows($ sq);

   if($ ness > 10) $ lmt = "LIMIT" . ($ ness - (8 + 1)) . ", 10", / / For the first index is 0!
   else $ lmt = "";

   $ sq2 = mysql_query("SELECT * FROM shoutbox ORDER BY id ASC" . $ lmt . " ")

   while($ msg = mysql_fetch_array($ sq2))
   (
      / / HERE YOU YOUR MESSAGE POSTERS
   )
?>
Reply With Quote
  #5  
Old 29-07-2010
Member
 
Join Date: Mar 2010
Posts: 202
Re: How to reverse an array

The ORDER BY id ASC posters you in the right order, but not the right messages, and the ORDER BY id DESC will show you the good, but in the wrong. It will therefore be a mix of both, should select the latest posts in the correct order. For the "LIMIT x, y, the first row x is 0 so if you have no entries in your database, the latter has a rank (n - 1) (the first row to 0, the second has a rank 1 etc. ...). If you want the last 8 messages, you must take as a starting point for the "LIMIT" the eighth before the final, which will thus rank ((n - 1) - 8). Except that in the code, number of messages n is represented by $ ness. Then, you want 8 posts, which gives:
Other - Select
Code:
LIMIT (($ ness - 1) - 8), 8
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to reverse an array"
Thread Thread Starter Forum Replies Last Post
How does Reverse SEO work Haleema Technology & Internet 5 13-07-2011 01:47 AM
How the reverse() function can be used in C++ BossBattle Software Development 5 20-02-2010 04:55 PM
Assigning an array to an array MACE Software Development 3 18-11-2009 05:19 PM
Reverse lookup a SID Kool Active Directory 1 20-07-2009 10:53 PM
What is Reverse Engineering? Amol21 Software Development 4 11-02-2009 09:04 PM


All times are GMT +5.5. The time now is 08:43 PM.