Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > Assistance needed with mysql query to achieve this php5
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 11th November 11:09
progwihz
External User
 
Posts: 1
Default Assistance needed with mysql query to achieve this php5



Hi all I have a table below

CREATE TABLE `friends` (
`id` int(11) NOT NULL auto_increment,
`member_id` int(11) NOT NULL,
`member` varchar(32) NOT NULL,
`friendwith` varchar(32) NOT NULL,
`friendWithId` int(11) NOT NULL,
`status` varchar(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=49 ;


I run the following query to get my friends

SELECT fc.friendWithId, fc.friendWith, uu.image_path, uu.first_name, uu.last_name, uu.city, uu.gender, uu.relationship_status, uu.last_login FROM friends fc JOIN users uu ON fc.friendWithId = uu.user_id WHERE member_id = '%s' AND member = '%s' and fc.status='active'

I need help on how to modify the sql query so that it not only displays people who am friends with but should also display people who are friends with me

What i currently have is a one way relationship, I am trying to modify the query to create a two way relationship.

Cheers


---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
  Reply With Quote


 


2 11th November 11:11
ceo
External User
 
Posts: 1
Default Assistance needed with mysql query to achieve this php5



Just take out member_id = '%s' and use friendWIthId = '%s' instead.

Actually, I think you may need to swap member/friendwith as well...

But why you are storing everybody's NAME twice is beyond me...

Or maybe I'm guessing wrongly what the fields are...


--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?
  Reply With Quote
3 11th November 11:13
progwihz
External User
 
Posts: 1
Default Assistance needed with mysql query to achieve this php5


Hi Richard, I'll try out your suggestions and will let you know if i had any luck.
The db structure is a little complicated hence the duplication of usernames.
Cheers

Actually, I think you may need to swap member/friendwith as well...

But why you are storing everybody's NAME twice is beyond me...

Or maybe I'm guessing wrongly what the fields are...

On Thu, January 24, 2008 10:49 am, Don Don wrote:


--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?


---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
  Reply With Quote
4 11th November 16:30
ceo
External User
 
Posts: 1
Default Assistance needed with mysql query to achieve this php5


A complicated DB is all the MORE reason not to duplicate data...


Stop typing and start thinking, because you are building up a mess
that WILL bite you in the butt in the long run...

Unless you've been doing SQL for 20 years and this IS one of the times
to break all the rules. :-)

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?
  Reply With Quote
Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Php 5 forum, Apache forum, Iis forum, Functions forum, Classes forum, Librarys forum, Bugs forum, Postgres forum, Mysql forum, Paradox forum, Ms sql forum, Configurations forum, Php.ini forum, Problems forum, Scripting forum, Css forum, General forums, Off-topic talk, Links, Extra forums, Php


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666