Jump to content
php.lv forumi

Recommended Posts

Posted

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?

Posted (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 by stencilz
Posted

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>';
  }

Posted

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.

Posted

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

×
×
  • Create New...