Use php to order by number and echo the last five rows (sql)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Use php to order by number and echo the last five rows (sql)

Post by JKM »

I want to select data from four different tables -> mix the data -> order by timestamp -> echo the data from the five last rows.
Example:

Code: Select all

TABLE 1
{
    row 1
    {
        title: 'data1blabla';
        type:   'Interview';
        ts:     1265634051;
    }
    
    row 2
    {
        title: 'data2blabla';
        type: 'Interview';
        ts: 1265634055;
    }
}
 
TABLE 2
{
    row 1
    {
        title: 'data3blabla';
        type:   'Trailer';
        ts:     1265634056;
    }
}
 
TABLE 3
{
    row 1
    {
        title: 'data4blabla';
        type:   'Gallery';
        ts:     1265634053;
    }
    
    row 2
    {
        title: 'data5blabla';
        type:   'Gallery';
        ts:     1265634061;
    }
}
 
 
TABLE 4
{
    row 1
    {
        title: 'data6blabla';
        type:   'Article';
        ts:     1265634052;
    }
}
OUTPUT:

Code: Select all

'data4blabla - Trailer - 1265634092'
'data8blabla - Article - 1265634078'
'data6blabla - Gallery - 1265634061'
'data3blabla - Trailer - 1265634056'
'data2blabla - Interview - 1265634055'
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Use php to order by number and echo the last five rows (sql)

Post by aravona »

You could use a join or union to draw information from multiple tables, then you can use the ORDER BY asc/desc to put it in order.

w3schools join
w3schools order by
Post Reply