PDA

View Full Version : Combining 3 queries - what to do with the same variable?


Erwin
07-30-2002, 11:16 PM
Hi,

Thanks for helping in advance.

I'm running into trouble combining another 3 queries - 2 of them use the same variables.



$test = $DB_site->query("
SELECT forum.title,user.userid,title,threadid,thread.last post,lastposter,replycount,views,postuserid,postus ername
FROM thread
LEFT JOIN forum USING (forumid)
LEFT JOIN user ON thread.lastposter=user.username
ORDER BY lastpost DESC LIMIT 5
");



How do I show the thread title AND the forum title?

I cannot use $test[title] since there are 2 title variables being called... how do I separate each title variable?

Also, is joining these 3 queries valid?

Thanks again for helping...

Admin
07-31-2002, 06:04 AM
You give the fields aliases (a MySQL term), like so:
$test = $DB_site->query("
SELECT forum.title AS forumtitle,user.userid,thread.title AS threadtitle,threadid,thread.lastpost,lastposter,re plycount,views,postuserid,postusername
FROM thread
LEFT JOIN forum USING (forumid)
LEFT JOIN user ON thread.lastposter=user.username
ORDER BY lastpost DESC LIMIT 5
");
And then use $row[forumtitle] and $row[threadtitle].

Erwin
07-31-2002, 07:55 PM
Firefly, thanks again for help. :) You are very gracious. It works fine.

Admin
08-01-2002, 08:35 AM
You're welcome. :)