SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need some mysql help

    Hello, I have two chunks of code which I need some help combining here.

    I have this facebook api call which gives me all the user_ids of the current logged in user's friends:

    $appusers=$facebook->api_client->friends_getAppUsers();

    foreach($appusers as $person) {
    $fqlresult = $facebook->api_client->fql_query("SELECT name FROM user WHERE uid=$person");
    $name=$fqlresult[0]['name'];


    echo $name;
    }


    And I have this which gives me all the link_id's that a specific user_id has voted on:

    $sql = "SELECT link_id FROM links, votes WHERE vote_user_id=$user->id AND vote_link_id=link_id AND link_status !='discard' $order_by LIMIT $rows";


    Instead I would like to have it so that sql statement fetches link_ids FROM links, votes WHERE vote_user_id=[any of the $name's from the first statement above]

    I'm not sure how to do that exactly, whether I would have vote_user_id=$some variable that is a list of all the $names with an OR operators between each (which doesn't seem to work anyway) or if there is a better way..

    Thanks in advance!
    -Gabe

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by gragland View Post
    Instead I would like to have it so that sql statement fetches link_ids FROM links, votes WHERE vote_user_id=[any of the $name's from the first statement above]
    Code:
    SELECT links.link_id 
      FROM user
    INNER
      JOIN votes
        ON votes.vote_user_id = user.name
    INNER
      JOIN links
        ON links.link_id = votes.vote_link_id
       AND links.link_status <> 'discard' 
     WHERE user.uid=$person
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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