0

On a project I am doing I am making a Feed Flow of recent updates. Problem is I cant find out to overcome the following.

There are two tables, shouts and journals. what I want to do is pull records from them both and print them out with the newest at the top and the oldest at the bottom.

I have tried every way and cant find how to do it, but heres the logic of what I am trying.

The two tables fields are

shouts = id, content, date, user
journals = id, content, title, date, user

SELECT * FROM shouts, journals ORDER BY id DESC;

While( $row = above statement )
{

if its a shout
{

print "Shout: $row";

} else {

print " Journal: $row <br> $row";

}

The final result of the flow should be something like

SHOUT
SHOUT
JOURNAL
SHOUT
JOURNAL

ect ect but at the moment all I can seem to get working is all journal or all shout


Any help Highly appreciated.


}

Edited by Mi-Dia: n/a

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by diafol
0
SELECT `id`,`content`,`date`,`user`, `title`, "j" AS `type`
FROM `journals`
UNION
SELECT `id`,`content`,`date`,`user`, NULL AS `title`, "s" AS `type`
FROM `shouts`
ORDER BY id DESC

The NULL as title is a must as UNION requires the same number of fields (and the same datatype). I've included `type` so when you loop through the resultset, you could easily identify which is which and e.g. provide some conditional formatting/colour scheme etc.

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.