Jump to content
php.lv forumi

select count(), kur nepieciešamas 2 tabulas


anonīms

Recommended Posts

t1 - turniri

`id`

`nosaukums`

`turnira_statuss`

t2 - turniru_dalibnieki

`id`

`lietotaja_id`

`turnira_id`

`komandas_id`

 

Ideja ir tāda, ka nepieciešams izvilkt count() statistikai

Cik turnīros piedalās. (Saskaitīt cik turnīros piedalās lietotājs, kas pašlaik ir ielogojies).

 

Mēģināju kaut ko "skrūvēt" kopā, bet šķiet, ka nekas nav izdevies.

 

 		$kilz0rkje = "SELECT count(bliezam_turniri.id) as tp_skaits
	FROM bliezam_turniru_dalibnieki, bliezam_turniri
	WHERE bliezam_turniri.turnira_statuss = '2' OR bliezam_turniri.turnira_statuss = '3' AND 
	bliezam_turniru_dalibnieki.lietotaja_id = '".$rows['id']."'
	";
	$tpps = mysql_query($kilz0rkje) or die(mysql_error());
	$tpps = mysql_fetch_array($tpps);
echo $tpps['ap_skaits'];

Kur varētu būt vaina?

 

Edit: Mans izvadītais skaitlis ir 390, kas ne tuvu nav patiess.

Edited by anonīms
Link to comment
Share on other sites

Tāpat izvadīts tiek pārmērīgi liels skaitlis

 		$kilz0rkje = "SELECT count(bliezam_turniri.id) as tp_skaits
	FROM bliezam_turniri, bliezam_turniru_dalibnieki
	WHERE bliezam_turniri.turnira_statuss = '2' OR bliezam_turniri.turnira_statuss = '3' AND 
	bliezam_turniru_dalibnieki.lietotaja_id = '".$rows['id']."' AND bliezam_turniru_dalibnieki.turnira_id=bliezam_turniri.id
	";

Link to comment
Share on other sites

Tāk.

 

		 $kilz0rkje = "SELECT count(bliezam_turniri.id) as tp_skaits
	FROM bliezam_turniri
	WHERE bliezam_turniri.turnira_statuss = '2' OR bliezam_turniri.turnira_statuss = '3' 
	";

 

skaitlis = 2

 

bet ja pieliek tā, tad ir 390

		 $kilz0rkje = "SELECT count(bliezam_turniri.id) as tp_skaits
	FROM bliezam_turniri, bliezam_turniru_dalibnieki
	WHERE bliezam_turniri.turnira_statuss = '2' OR bliezam_turniri.turnira_statuss = '3' 
	";

Edited by anonīms
Link to comment
Share on other sites

SELECT COUNT(bliezam_turniri.id) AS tp_skaits FROM `bliezam_turniri`, `bliezam_turniru_dalibnieki` WHERE bliezam_turniri.turnira_statuss IN (2,3) AND bliezam_turniru_dalibnieki.lietotaja_id=$id AND bliezam_turniru_dalibnieki.turnira_id=bliezam_turniri.id

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...