solgun Posted October 6, 2007 Share Posted October 6, 2007 Hi, i have a table with this Structure: ID || Inviter || Reciever 1 || test@test.com || test1@test.com 2 || test@test.com || test2@test.com 3 || test@test.com || test3@test.com 4 || test3@test.com || test1@test.com Information: test@test.com has 3 invitations test1@test.com has 2 invitations test3@test.com has 2 invitations test2@test.com has 1 invitation i want an query to read the invitations made by his own inviters Example: test2@test.com has 1 inviter that is test@test.com(wich this one as 3), i want this query to show the other two inviters... wich are test1@test.com and test3@test.com. This is what i've got so far but no success, i get inviters that the same inviter already as. $testinv=mysql_query("SELECT Inviter, Reciever FROM invitations WHERE Inviter='$_SESSION[user]' OR Reciever='$_SESSION[user]' ORDER BY RAND() LIMIT 1"); ////// Gets a Random Friend of him $testrow=mysql_flech_array($testinv); if ($testrow['Inviter'] != $_SESSION['user']) $testrow=$dameamgdoamg1['Inviter']; else $testrow=$testrow['Reciever']; ////// Choose the one that is not himself $testinv1=mysql_query("SELECT Inviter, Reciever FROM invitations WHERE Inviter='$testrow' AND Inviter!='$_SESSION[user]' AND Reciever !='$_SESSION[user]' OR Reciever='$testrow' AND Inviter!='$_SESSION[user]' AND Reciever !='$_SESSION[user]' ORDER BY RAND() LIMIT 1"); ////// Gets the Inviter of his Inviter $testrow1=mysql_flech_array($testinv1); if ($testrow1['Inviter'] != $testrow) $testrow1=$testrow1['Inviter']; else $testrow1=$testrow1['Reciever']; /////// Choose the one that is not himself echo $testrow1.' invited your inviter '.$testrow i hope you understand where im getting, and find a way out to this headshake i have.... Thank you all Quote Link to comment Share on other sites More sharing options...
Barand Posted October 6, 2007 Share Posted October 6, 2007 try SELECT a.receiver FROM invites a INNER JOIN invites b ON a.inviter = b.inviter WHERE b.receiver = 'test2@test.com' AND a.receiver <> b.receiver Quote Link to comment Share on other sites More sharing options...
solgun Posted October 7, 2007 Author Share Posted October 7, 2007 Well can you discribe all the steps and why is INNER JOIN standing there for? im like NULL to mysql query ??? Quote Link to comment Share on other sites More sharing options...
solgun Posted October 7, 2007 Author Share Posted October 7, 2007 btw i don't want to get inviters that are already mine too... ??? ??? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 7, 2007 Share Posted October 7, 2007 The join is to match records. You describe the "steps" in your example Quote Link to comment Share on other sites More sharing options...
solgun Posted October 7, 2007 Author Share Posted October 7, 2007 yea well but how can i make it get only inviters that arent mine already? ??? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 7, 2007 Share Posted October 7, 2007 test2 was invited by test test also invited test1 and test3 the query gives test1, test3 If you wanted something else, please explain. Quote Link to comment Share on other sites More sharing options...
solgun Posted October 7, 2007 Author Share Posted October 7, 2007 well it gives me also test@test.com ??? no matter if its invited or the inviter i want it only to show they are connected to each one... example: for test3@test.com i would get just test2@test.com thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted October 7, 2007 Share Posted October 7, 2007 As it only selects the receiver column, and there is no test@test.com in that column in your sample data above, I don't see how that can happen unless you've changed the query or the data. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 7, 2007 Share Posted October 7, 2007 Example: test2@test.com has 1 inviter that is test@test.com(wich this one as 3), i want this query to show the other two inviters... wich are test1@test.com and test3@test.com. You say "the other two inviters" but test1 only appears in receivers column, so do you mean receivers, or are you working with one set of data but posting another? example: for test3@test.com i would get just test2@test.com explain the logic for that statement, please Quote Link to comment Share on other sites More sharing options...
solgun Posted October 7, 2007 Author Share Posted October 7, 2007 Ohh i think there is something missing here, i will example one sitiuation that will clear everything... Example: I(a) invite someone(b) but someone© invites me too(a) So the table would be like: ID || Inviter || Reciever 1 || a || b 2 || c || a This leaves me with 2 invitations(invited b, and got invited by c). what i want is b getting c. Other example more complex: ID || Inviter || Reciever 1 || a || b 2 || c || a 3 || d || a 4 || a || e 5 || d || c for b i get a, d and e. for c i get b and e. for a i get none since he as everyone for e i get a for d i get a and c Don´t matter what collumn it belongs(Inviter or Reciever). i hope i made myself clear and you find out a way out to this mess. Thank you very much Quote Link to comment Share on other sites More sharing options...
solgun Posted October 18, 2007 Author Share Posted October 18, 2007 seems that no one likes me blah! Quote Link to comment Share on other sites More sharing options...
lewis987 Posted October 18, 2007 Share Posted October 18, 2007 dont you guys ever read code? $testrow=mysql_flech_array($testinv); Should Be: $testrow=mysql_fetch_array($testinv); i just checked the php site and there is no function named mysql_flech_array Quote Link to comment Share on other sites More sharing options...
solgun Posted October 19, 2007 Author Share Posted October 19, 2007 well i writed the code just for the example, its not really my code. besides thats not the problem i discribe at all Quote Link to comment Share on other sites More sharing options...
solgun Posted November 3, 2007 Author Share Posted November 3, 2007 not being helped at all ??? ??? Quote Link to comment Share on other sites More sharing options...
fenway Posted November 5, 2007 Share Posted November 5, 2007 not being helped at all ??? ??? What is the query you have right now? What results is it producing? What results do you want it to produce? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.