solgun Posted October 6, 2007 Share Posted October 6, 2007 Hi, i have a table with this Structure: ID || Inviter || Reciever 1 || [email protected] || [email protected] 2 || [email protected] || [email protected] 3 || [email protected] || [email protected] 4 || [email protected] || [email protected] Information: [email protected] has 3 invitations [email protected] has 2 invitations [email protected] has 2 invitations [email protected] has 1 invitation i want an query to read the invitations made by his own inviters Example: [email protected] has 1 inviter that is [email protected](wich this one as 3), i want this query to show the other two inviters... wich are [email protected] and [email protected]. 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 Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/ 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 = '[email protected]' AND a.receiver <> b.receiver Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-363606 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 ??? Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-363741 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... ??? ??? Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-363743 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 Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-363901 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? ??? Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-363955 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. Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-363985 Share on other sites More sharing options...
solgun Posted October 7, 2007 Author Share Posted October 7, 2007 well it gives me also [email protected] ??? no matter if its invited or the inviter i want it only to show they are connected to each one... example: for [email protected] i would get just [email protected] thanks Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-364105 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 [email protected] 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. Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-364111 Share on other sites More sharing options...
Barand Posted October 7, 2007 Share Posted October 7, 2007 Example: [email protected] has 1 inviter that is [email protected](wich this one as 3), i want this query to show the other two inviters... wich are [email protected] and [email protected]. 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 [email protected] i would get just [email protected] explain the logic for that statement, please Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-364114 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 Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-364188 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! Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-372219 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 Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-372693 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 Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-373082 Share on other sites More sharing options...
solgun Posted November 3, 2007 Author Share Posted November 3, 2007 not being helped at all ??? ??? Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-384009 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? Link to comment https://forums.phpfreaks.com/topic/72100-headshake-with-a-query/#findComment-385136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.