Click to See Complete Forum and Search --> : Check DB if True
dclamp
Jan 25th, 2007, 04:10 PM
ok, so i have a members_friends table. like this:
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?
superbovine
Jan 25th, 2007, 05:30 PM
http://dev.mysql.com/doc/refman/5.0/en/join.html
happy reading!
kows
Jan 26th, 2007, 01:16 AM
As long as you know your MySQL basics (or even if you don't, I guess), I would suggest this (http://www.keithjbrown.co.uk/vworks/mysql/mysql_p5.php) 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.
dclamp
Jan 26th, 2007, 08:19 AM
Thanks so much kows! I am horrible with joins, i dont know why... I just dont understand them, but that tutorial helped.
THanks.
dclamp
Jan 26th, 2007, 11:50 PM
would this be correct?:
SELECT *
FROM `members_friends`
WHERE member_friends.member_id='".$_GET['member_id']."'
AND member_friends.friend_id='".$_SESSION['member_id']."'
dclamp
Jan 27th, 2007, 12:20 AM
i dont think i need inner join if it is the on the same table do i?
kows
Jan 27th, 2007, 12:47 PM
why don't you just try and see if it did what you wanted or not?
dclamp
Jan 27th, 2007, 12:48 PM
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.
visualAd
Jan 27th, 2007, 07:12 PM
The SQL you need is quite simple. I suggest you learn it:
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.