...

View Full Version : Simple query help?



stfc_boy
08-15-2008, 10:33 AM
Hi All,

Really simple one which hopefully you will be able to help me with:

I have a query which works fine



<?php
// select all records ordered by date
$r = mysql_query("Select * FROM news ORDER BY news_id desc LIMIT 6");
while($topStory = mysql_fetch_array($r)) {
$topHead[] = $topStory['headline'];
$topPic[] = $topStory['front_picture'];
$topOpening[] = $topStory['opening'];
}
?>


But instead of using this query I want to use this one with the above code




$query = "(SELECT news_id as id, published as sdate, front_picture, headline, opening, 'c' AS tbl FROM news) UNION ALL
(SELECT match_id as id, match_date as sdate, front_picture, headline, opening, 't' AS tbl FROM matchday_live_details) UNION ALL
(SELECT report_id as id, match_date as sdate, front_picture, headline, opening, 's' AS tbl FROM reports) ORDER BY sdate desc, id desc LIMIT 6";


How would I do that?

Thanks

bacterozoid
08-15-2008, 12:50 PM
Like this:




<?php
$query = "(SELECT news_id as id, published as sdate, front_picture, headline, opening, 'c' AS tbl FROM news) UNION ALL
(SELECT match_id as id, match_date as sdate, front_picture, headline, opening, 't' AS tbl FROM matchday_live_details) UNION ALL
(SELECT report_id as id, match_date as sdate, front_picture, headline, opening, 's' AS tbl FROM reports) ORDER BY sdate desc, id desc LIMIT 6";

// select all records ordered by date
$r = mysql_query($query);

while($topStory = mysql_fetch_array($r, MYSQL_ASSOC)) {
$topHead[] = $topStory['headline'];
$topPic[] = $topStory['front_picture'];
$topOpening[] = $topStory['opening'];
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum