Jump to content

"Latest" box


Azzyh

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/188393-latest-box/
Share on other sites

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";
}

Link to comment
https://forums.phpfreaks.com/topic/188393-latest-box/#findComment-994550
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/188393-latest-box/#findComment-994659
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.