killfall Posted August 7, 2008 Share Posted August 7, 2008 Hi there, I have made a website which is based on blogs. Each blog is stored in a seperate table with the fields "id, time, date, blog, image_id" then I have another table called image which has links to all the images used in the blog and then has and image id in which the blog image id refers to. I want to make a query which uses an array to got more than 1 blog (2 at a time) but looks in both tables, the blog table for the blog itself, then the images table for the corresponding image. The code I have now uses the printf() function but I have done it wrong and am not sure whats wrong or right or what. <?$ query = mysql_query("SELECT *.favourite, link.image, image_id.image FROM favourite, image WHERE image_id.favourite=image_id.image ORDER BY date.favourite DESC") or die(Error); while ($row = mysql_fetch_array($query, MYSQL_BOTH)) { printf("<table width='100%%' border='0' cellspacing='0'><tr><td width='50%%'>%s</td><td width='50%%'>%s</td></tr><tr><td colspan='2'>%s<a href='%s'><img src='%s' width='50' height='50' align='right'></a></td></tr></table>", $row["time.favourite"], $row["date.favourite"], $row["blog.favourite"], $row["link.favourite"], $row["link.image"]); } mysql_free_result($query); ?> *favourite being the blog table BTW Link to comment https://forums.phpfreaks.com/topic/118704-solved-select-multiple-tables/ Share on other sites More sharing options...
elflacodepr Posted August 7, 2008 Share Posted August 7, 2008 you can use the JOIN or UNION statement. Link to comment https://forums.phpfreaks.com/topic/118704-solved-select-multiple-tables/#findComment-611187 Share on other sites More sharing options...
killfall Posted August 8, 2008 Author Share Posted August 8, 2008 Perfect thanks alot Link to comment https://forums.phpfreaks.com/topic/118704-solved-select-multiple-tables/#findComment-612063 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.