Forum Moderators: coopster

Message Too Old, No Replies

PHP: sorting arrays

that have keys and values...

         

freshmold

3:27 am on Apr 6, 2003 (gmt 0)

10+ Year Member



Hey!

I'm trying to determine the most recent post from 5 mysql tables. I'm doing this by calling the last post from the five tables and making variables from them (based on the date).

Then, these variables are put into an array with a key => val thing to name the table they came from:


$lastarray = array (
$last_table1 => "forum_table1_post",
$last_table2 => "forum_table2_post",
$last_table3 => "forum_table3_post",
$last_table4 => "forum_table4_post",
$last_table5 => "forum_table5_post"
);

Then the plan was this:
1. ksort that array by the date ($last_tablex)
2. get the most recent date from the array
3. have two variables that represent the most recent date and the table it's from.

Does that make sense? How do I get that information?

OR

Is there a better way to find the most recent post of the 5 mysql tables?

Thanks in advance.

- fresh

jatar_k

7:09 pm on Apr 6, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would think you could select it with mysql.

is there anyway to use joins in the query and use MAX or ORDER BY and grab the firt result?

Lisa

10:08 pm on Apr 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds rather simple.

How about a new table that keeps track of posts to all tables! Then you can select all this information in one simple statement. Call this new table, last_post.

table
datetime
(other fields if you want. Like: title, author, desc)

This keeps your selects down to just one, Instead of five! If you are displaying this information everytime a person visits your site. The one select statement would be better.