Azzyh Posted January 13, 2010 Share Posted January 13, 2010 Hello phpfreaks.com! I want to learn how to make a script, that receives the latest column inserted in 3 tables, and then shows them with fields title and date. Checks for the last column by the latest id... order by id maybe? I dont know how to do this, as i never had that in thought. Ive seen this happend in many sites, and in forums like "Latest posts" where its a box showing the poster's username and the title of the thread. So i know this is possible. Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 13, 2010 Share Posted January 13, 2010 You mean the latest row(s) not columns. Yes, it is as easy as sorting by a field and getting the first n records. Here is an example which you would need to modify according to your particular database: //Create query to get last 5 records based upon date field $query = "SELECT field1, field2, field3 FROM table ORDER BY date DESC LIMIT 0, 5"; $result = mysql_query($query); while($record = mysql_fetch_assoc($result)) { echo "{$record['field1']}, {$record['field2']}, {$record['field3']}<br />\n"; } Quote Link to comment Share on other sites More sharing options...
Azzyh Posted January 13, 2010 Author Share Posted January 13, 2010 What if i want to get from 3 table's and not just 1 ? thanks for reply Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 14, 2010 Share Posted January 14, 2010 Depends on what you mean. If you are referring to three tables that are related and you need data for a total of three recordsets of combined data from those three tables then you would need to use joins. However, if you need three different sets of records each from each table then just run three queries. 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.