Results 1 to 9 of 9

Thread: Check DB if True

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Check DB if True

    ok, so i have a members_friends table. like this:

    Code:
    member_id     friend_id
    ------------------------
        1      |       4
        2      |       4
        3      |       4
    
    This meaning, That member '4' is friends to 1, 2, 3.
    
    member_id     friend_id
    ------------------------
        4      |       1
        4      |       2
        4      |       3
    
    This meaning that Members 1, 2, 3 are friends of 4.
    What i need to do is look through the database to see if member '4' has friend '1' as a friend.

    How do i do this?
    My usual boring signature: Something

  2. #2
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: Check DB if True


  3. #3
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Check DB if True

    As long as you know your MySQL basics (or even if you don't, I guess), I would suggest this instead. I always found user-made tutorials for MySQL much easier to comprehend and read through, as long as they were well written and not made by people who say "u" -- or people who think they know what they're talking about, but really don't.

    In fact, I was going to make a new topic illustrating my MySQL problem because I couldn't make sense of the official documentation -- so I Googled quickly instead to save myself from having to post and wait for a reply, and the link above was the link to the solution of my problem.

    But anyway, yeah, joins are what you're looking for.

  4. #4

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Check DB if True

    Thanks so much kows! I am horrible with joins, i dont know why... I just dont understand them, but that tutorial helped.

    THanks.
    My usual boring signature: Something

  5. #5

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Check DB if True

    would this be correct?:

    Code:
    SELECT * 
    FROM `members_friends` 
    WHERE member_friends.member_id='".$_GET['member_id']."' 
    AND member_friends.friend_id='".$_SESSION['member_id']."'
    My usual boring signature: Something

  6. #6

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Check DB if True

    i dont think i need inner join if it is the on the same table do i?
    My usual boring signature: Something

  7. #7
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Check DB if True

    why don't you just try and see if it did what you wanted or not?

  8. #8

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Check DB if True

    Quote Originally Posted by kows
    why don't you just try and see if it did what you wanted or not?
    i have. i have changed it like 6 diffrent times and it still doesnt work.
    My usual boring signature: Something

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Check DB if True

    The SQL you need is quite simple. I suggest you learn it:
    Code:
    SELECT
        friend_id
    FROM
        member_friends mf
    WHERE
        mf.member_id=<memberID> AND
        mf.friend_if=<friendID>;
    There is no need to use a join here because you are not sourcing data from another relation and you should certainly not join the table to itself.

    Ensure that you escape any variables inserted into the query from outside. In actual fact you should use parametrized queries.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width