Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts

    Simple query help?

    Hi All,

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

    I have a query which works fine

    PHP Code:
    <?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


    PHP 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

  • #2
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    Like this:

    PHP Code:

    <?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($rMYSQL_ASSOC)) {
    $topHead[] = $topStory['headline'];
    $topPic[] = $topStory['front_picture'];
    $topOpening[] = $topStory['opening'];
    }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •