stencilz Posted April 9, 2007 Report Share Posted April 9, 2007 ir tabula referal un tabula users referal tabulā ir id un tas pats ir tabulā users vajadzētu lai parāda sagrupētus lietotājus pēc rindu skaita ar to id referal tabulā Kā to lai izdara? Link to comment Share on other sites More sharing options...
Delfins Posted April 9, 2007 Report Share Posted April 9, 2007 count() + group by Link to comment Share on other sites More sharing options...
stencilz Posted April 10, 2007 Author Report Share Posted April 10, 2007 nu ja es darīšu tā tad man parādīs vienu lietotāju vairākas reizes. tas ir jādara vienā kverijā? Link to comment Share on other sites More sharing options...
andrisp Posted April 10, 2007 Report Share Posted April 10, 2007 Jaa, vienaa. Grupee peec lietotaaja ID, tad neraadiisies vairaakas reizes. Link to comment Share on other sites More sharing options...
stencilz Posted April 10, 2007 Author Report Share Posted April 10, 2007 (edited) es zinu ka nepareizi bet vismaz uz to pusi ir? $q = musql_query("SELECT t1.COUNT(*),t2.id FROM referal t1, users t2 WHERE t1.id=t2.id ORDER BY t2.id"); while($x = mysql_fetch_row($q)) { bla bla } Edited April 10, 2007 by stencilz Link to comment Share on other sites More sharing options...
andrisp Posted April 10, 2007 Report Share Posted April 10, 2007 Par group by aizmirsi. Link to comment Share on other sites More sharing options...
stencilz Posted April 10, 2007 Author Report Share Posted April 10, 2007 jā tiešām aizmirsu. bet vai tad COUNT(*) nav jābūt kopā ar mysql_fetch_row(); ? Link to comment Share on other sites More sharing options...
rpr Posted April 10, 2007 Report Share Posted April 10, 2007 iespeejams ka tu jauc mysql_num_rows ar sql select sintaksi. palasi sho: http://dev.mysql.com/doc/refman/5.0/en/select.html Link to comment Share on other sites More sharing options...
stencilz Posted April 10, 2007 Author Report Share Posted April 10, 2007 iespējams ka daudz ko jaucu :) šeit ir strādājošs kods, bet kā lai iztaisa lai groupē sākot ar lietotāju kuram visvairāk rindu referal tabulā? $q = mysql_query("SELECT t1.id,t1.user_name FROM users t1,referal t2 WHERE t1.id=t2.id GROUP BY t1.id"); while($x = mysql_fetch_array($q)) { list($y) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM referal WHERE id='".$x['id']."'")); echo '<p>'.$x['user_name'].' ('.$y.')</p>'; } Link to comment Share on other sites More sharing options...
andrisp Posted April 10, 2007 Report Share Posted April 10, 2007 No tava pirmā kverija nav nekādas jēgas, ja tu šitā dari. SELECT t1.id, t1.user_name, COUNT(t1.*) as refs FROM users t1,referal t2 WHERE t1.id=t2.id GROUP BY t1.id Šitā nesanāk ? PS. Tu kaut kā dīvaini veido esi nosaucis referal kolonnas. id vietā vajadzētu izmanto user_id vai ko tamlīdzīgu. Link to comment Share on other sites More sharing options...
stencilz Posted April 10, 2007 Author Report Share Posted April 10, 2007 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) as refs FROM users t1,ref t2 WHERE t1.id=t2.id GROUP BY Link to comment Share on other sites More sharing options...
andrisp Posted April 10, 2007 Report Share Posted April 10, 2007 COUNT(t1.*) vietā vienkārši COUNT(*) Link to comment Share on other sites More sharing options...
stencilz Posted April 10, 2007 Author Report Share Posted April 10, 2007 nu jā šādi sanāk. paldies par palīdzību Link to comment Share on other sites More sharing options...
Recommended Posts