reGative Posted July 27, 2012 Report Share Posted July 27, 2012 (edited) Labdien! Esmu uztaisījis draugu sistēmu. Bet netieku es ar vienu lietu galā - ar draudzības apstiprinājumiem viss ok, bet iznāk viena štelle. Ir trīs draugi - A, B un C. A uzaicina B. A redz B savā draugu sarakstā, bet B redz sevi savā draugu sarakstā. Un ja C uzaicina A, tad C savā draugu sarakstā redz A, bet A redz B un sevi savā draugu sarakstā. MySQL pieprasījums draugu sarakstam (te arī ir problēma): <?php public function get_list_of_friends($invited_id) { return DB::select('friends.*', 'users.*') ->from('friends') ->join('users') ->on('users.id', '=', 'friends.invitor_id') ->where('friends.status', '=', 'accepted') ->and_where('friends.invitor_id', '=', $invited_id) ->or_where('friends.status' ,'=', 'accepted') ->and_where('friends.invited_id', '=', $invited_id) ->as_object() ->execute(); } Te arī ir shēmas tabulām 'users' un 'friends': https://gist.github.com/3186697 Ceru, ka kādam radīsies ideja, kā to varētu uztaisīt. Edited July 27, 2012 by reGative Quote Link to comment Share on other sites More sharing options...
y2ok Posted July 27, 2012 Report Share Posted July 27, 2012 (edited) Kāpēc tev atkārtojas where nosacījumi ? ->where('friends.status', '=', 'accepted') ->and_where('friends.invitor_id', '=', $invited_id) ->or_where('friends.status' ,'=', 'accepted') ->and_where('friends.invited_id', '=', $invited_id Kā arī man liekas, ka būtu vieglāk glabāt kaut kā šādi draugus - // id // user_id // friends // pending_friends ----------------------------------------------------- // 1 // 1 // 5, 4 // 3, 6, 2 // 2 // 2 // 3 , 4 , 6 , 5 , 9 // 1, 7 ... Un tad vienkārši varētu no šīs tabulas izvilkt pašreizējā usera draugus, un tālāk ar drauga id, sameklēt viņu info no vajadzīgās tabulas. Edited July 27, 2012 by y2ok Quote Link to comment Share on other sites More sharing options...
aaxc Posted July 27, 2012 Report Share Posted July 27, 2012 (edited) . Edited July 27, 2012 by aaxc Quote Link to comment Share on other sites More sharing options...
y2ok Posted July 27, 2012 Report Share Posted July 27, 2012 (edited) @aaxc: ir arī poga delete. Tas tā, turpmākai zināšanai, lai tukšus postus, varētu nelasīt. Edited July 27, 2012 by y2ok Quote Link to comment Share on other sites More sharing options...
aaxc Posted July 27, 2012 Report Share Posted July 27, 2012 Tas tā, turpmākai zināšanai... Quote Link to comment Share on other sites More sharing options...
y2ok Posted July 27, 2012 Report Share Posted July 27, 2012 (edited) Ehh, nemaz nezināju. Visu cieņu, atvainojos ;)! Edited July 27, 2012 by y2ok 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.