Jump to content
php.lv forumi

SQL/PHP Kverijs ar count + select iekšs select


anonīms

Recommended Posts

Neesmu nekad šādas "izvirtības" veidojis, bet doma ir tāda.

Pašlaik rangs tiek sadalīts starp visiem spēlētājiem, kaut arī viņi teiksim noteikto spēli nav vispār spēlējuši nevienu reizi. Tad nu šādu iespēju vajag izslēgt.

Patreizējais kods

mysql_query("UPDATE ".PREFIX."lietotaji SET ".$game."_now_rank = @i".$game."_now_rank := @i".$game."_now_rank + 1 ORDER BY ".$game."_rating DESC, id ASC") or die(mysql_error());

Mans "testa kods"

      mysql_query("UPDATE ".PREFIX."lietotaji SET ".$game."_now_rank = @i".$game."_now_rank := @i".$game."_now_rank + 1 
     WHERE 
     (SELECT count(t1.kas_spele) FROM ".PREFIX."1_tipa_speeles AS t1, ".PREFIX."tournaments AS t2 WHERE t2.game = '".$game."' AND ".PREFIX."lietotaji.id = t1.kas_spele) > 0
     ORDER BY ".$game."_rating DESC, id ASC") or die(mysql_error());

Problēma ir tur, ka visi, kuri nav spēlējuši arī tiek skaitīti kaut arī viņiem reitinga punkti ir 0.

Kur varētu būt problēma?

 

EDIT: + mistiski rangu sāk dot tikai no 22 cipara. o0

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

Ko, ko Grey_Wolf? :D

Nu izmanto tachu SQL IF/ELSE iespejas. Updeitam izmanto tikai tos ierakstus kas atbilst noteiktam kriterijam, ne tikai peec WHERE bet papildus arii peec IF/ELSE.

---

SQL lieliski tiek gala ar logiku ( IF/ELSE; AND; OR )

Edited by Grey_Wolf
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...