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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    list results from different tables depending on search result

    Hello all,

    I hope someone is able to help me out or lead me towards some links. That will be great. Many thanks in advance.

    ---

    What I have:
    I have a table 'aaa' where I search for a special time using row '111', showing the result on a xml page where I will get a listing of all results
    [-> see code]


    What I'm looking for:
    I would like to show more information related to the result which is not in the same table 'aaa'. I want to show row 'b1b1b1', 'b2b2b2', ... from table 'bbb' which has row 'xxx' in common with table 'aaa'.

    Database:
    table 'aaa'
    row '111', '222', ..., 'xxx'

    table 'bbb'
    row 'b1b1b1', 'b2b2b2', ..., 'xxx'


    How do I join the results and show them?

    ---

    $query = "SELECT * FROM aaa WHERE 111 >= curdate() AND 111 <= curdate() + INTERVAL 400 DAY";
    $result = mysql_query($query);

    if (!$result) {
    die('Invalid query: ' . mysql_error());
    }

    header("Content-type: text/xml");
    echo '<markers>';
    while ($row = @mysql_fetch_assoc($result)){
    echo '<marker ';
    echo 'valid="' . $row['111'] . '" ';
    echo '/>';
    }
    echo '</markers>';

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,869
    Thanks
    2
    Thanked 163 Times in 158 Posts
    You need to use a join clause in the select statement to join/associate the 2 tables.

    mysql join syntax

  • #3
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you!
    I tried this in the beginning and looked further. Now I went back and found my mistake, I have used table.row instead of table after JOIN.

    Thanks again


  •  

    Posting Permissions

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