Results 1 to 4 of 4
  1. #1

    Load Two MySQL Tables at Once

    Hey everyone, I found a thread on here via Google about loading two MySQL tables at once.. I am in need of doing that but with checking one of those tables also.

    My game allows users to become friends with certain members, once they are friends they are added into my database (crew_log)

    In another section I would like the users to be able to fight against all the users who are registered with the game but not include their friends/crew in the list

    Right now I am using this

    Code:
    if( $pirate->level==1 OR $pirate->level==2 ) $lowerLevel = 1;
    else $lowerLevel = ($pirate->level - 20);
    
    $upperLevel = ($pirate->level + 20);
    
    $res = query("SELECT * FROM `appusers` WHERE `uLevel`>=$lowerLevel AND `uLevel`<=$upperLevel AND `userid`!=$user ORDER BY RAND() LIMIT 0,30");
    appusers is a table where users are stored.

    I want to pull that info but the crew_log holds the information of who is friends, is there anyway of combining them so that if two users are friends they will not show up in the battle list?

    Crew Log holds just logId userid crewid (userID being the the players ID and the crewID being the friends ID)

    Example of what I mean

    Player 1 and Player 2 become friends, Player 1 decides to go battle and loads the list of users and Player 2 does not show up in that list because they are crew together

    I was thinking of something like this which kind of works but I am not sure how to properly phrase the query

    PHP Code:
    if( !empty($_GET[id]) ) {
        
    $theUser $_GET[id];
    }
    else {
        
    $theUser $user;
    }

    if( !
    check_if_crew$user$theUser ) ) {
        echo 
    'not sure what query to replace this echo with';
    } else { 
    Any help would be very much appreciated, been stuck on this for awhile now and can't figure it out
    i don't have SFW websites anymore

  2. #2
    Join Date
    Jan 2008
    Location
    St. John's, NL
    Posts
    2,114
    SELECT * FROM appusers LEFT JOIN crew_log ON appusers.id = crew_log.userID WHERE appusers.id != crew_log.userID

    Not tested, but should get you a list of all users that are not their friends.
    Cpanel/WHM PHP Perl Ruby Full Time Support
    LCWSoft - Canada web hosting (based in Newfoundland) since 2007
    Servers based in the US and Canada (Uptime Report)

  3. #3
    Join Date
    Jan 2008
    Location
    St. John's, NL
    Posts
    2,114
    You can also use the following query:

    SELECT * FROM appusers, crew_log WHERE appusers.id != crew_log.userID
    Cpanel/WHM PHP Perl Ruby Full Time Support
    LCWSoft - Canada web hosting (based in Newfoundland) since 2007
    Servers based in the US and Canada (Uptime Report)

  4. #4
    Join Date
    Jan 2008
    Location
    St. John's, NL
    Posts
    2,114
    You may also want to make sure you sanitize your user input from $_GET and $_POST variables, as you could get an SQL injection otherwise.
    Cpanel/WHM PHP Perl Ruby Full Time Support
    LCWSoft - Canada web hosting (based in Newfoundland) since 2007
    Servers based in the US and Canada (Uptime Report)

Similar Threads

  1. mysql deleted several tables under high server load
    By mrlugal in forum Hosting Security and Technology
    Replies: 0
    Last Post: 04-27-2007, 03:41 PM
  2. Replies: 19
    Last Post: 10-16-2006, 01:45 AM
  3. Two MySQL Tables
    By Rob83 in forum Programming Discussion
    Replies: 7
    Last Post: 07-10-2005, 11:03 AM
  4. MySQL tables inside tables
    By Lem0nHead in forum Hosting Security and Technology
    Replies: 3
    Last Post: 09-25-2004, 09:05 PM
  5. MySQL tables
    By MarieQ in forum Web Hosting
    Replies: 3
    Last Post: 11-16-2000, 04:41 PM

Posting Permissions

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