Page 1 of 1

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

Posted: Mon Feb 08, 2010 7:21 am
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'

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

Posted: Mon Feb 08, 2010 7:34 am
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