$5 Php Mysql Query Help

Discussion in 'Design Contests' started by 45n5, Jun 11, 2007.

  1. #1
    I'm struggling with a query in php and was wondering if anybody could take a stab at it. Reward is $5 send via paypal.

    I have a table of users and their friends like this

    Table1
    --username--userfriend--
    --mark-------melissa----
    --mark-------tommy----
    --mark-------cindy-----
    --melissa-----phillip-----

    I have another table with cds they own

    --username--cd---------------purchasedate---
    --melissa-----purple raine------5-7-07
    --melissa-----dance tonight----5-12-07
    --tommy-----dock of the bay---5-01-07

    Given a username, I want the query to grab all of the users friends, then grab the latest albums the friends have added.

    Example - if I query for mark it should tell me what albums mark's friends have added lately. The album table also contains other data I'd like to pull into the results

    So if mark went to his "friends" page, it would show his friends latest albums.

    Any thoughts? I need the query and php to loop through results. Thanks.
     
    45n5, Jun 11, 2007 IP
  2. 121603

    121603 Peon

    Messages:
    933
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    $query = "select a.userfriend as friend, b.cd as cd, b.otherdata as data from table1 a, table2 b where a.userfriend=b.username";

    $rs = mysql_query($query);

    while($row = mysql_fetch_assoc($rs)){
    echo $row['friend']." ".$row['cd']." ".$row['data'];
    }

    something like that.. :)
     
    121603, Jun 11, 2007 IP
  3. 45n5

    45n5 Peon

    Messages:
    414
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    cool, seems to be working, pm me your paypal

    thanks
     
    45n5, Jun 11, 2007 IP