MārisL Posted December 8, 2007 Report Share Posted December 8, 2007 Tātad man db ir 2 kollonas. rez1 un rez2 Kā varētu saskaitīt cik reizes rez1 > rez2, rez1 = rez2, rez1 < rez2? Link to comment Share on other sites More sharing options...
p4F Posted December 8, 2007 Report Share Posted December 8, 2007 $saskaitiit = mysql_query("SELECT count(*) as cnt FROM users where rez1 > rez2"); $saskaitiit = mysql_fetch_array($saskaitiit); $saskaitiit = $saskaitiit[cnt]; Link to comment Share on other sites More sharing options...
bubu Posted December 8, 2007 Report Share Posted December 8, 2007 SELECT SUM(rez1 > rez2), SUM(rez1=rez2), SUM(rez1<rez2) FROM tabule Link to comment Share on other sites More sharing options...
MārisL Posted December 9, 2007 Author Report Share Posted December 9, 2007 Syntax'es kļūda include "_inc_/config.php"; $q = mysql_query("SELECT SUM(rez1>rez2), SUM(rez1=rez2), SUM(rez1<rez2) FROM cw_rezultati"); $result = mysql_query($q) or die(mysql_error()); // Parādam datus while($row = mysql_fetch_array($result)) { echo "Spēles uzvarētas: ". $row['SUM(rez1>rez2)']. ""; echo "<br />"; } Link to comment Share on other sites More sharing options...
Delfins Posted December 9, 2007 Report Share Posted December 9, 2007 kļūda kur? Link to comment Share on other sites More sharing options...
Grey_Wolf Posted December 9, 2007 Report Share Posted December 9, 2007 (edited) MārisL --> saja vieta // echo "Spēles uzvarētas: ". $row['SUM(rez1>rez2)']. ""; // echo "Spēles uzvarētas: ". $row[0]. ""; vai nu SELECT SUM(rez1 > rez2) AS rez1, SUM(rez1=rez2) AS rez2 , SUM(rez1<rez2) AS rez3 FROM tabule tad var : echo "Spēles uzvarētas: ". $row['rez1']. ""; Edited December 9, 2007 by Grey_Wolf Link to comment Share on other sites More sharing options...
MārisL Posted December 9, 2007 Author Report Share Posted December 9, 2007 (edited) include "_inc_/config.php"; $q = mysql_query("SELECT SUM(rez1>rez2), SUM(rez1=rez2), SUM(rez1<rez2) FROM cw_rezultati"); $result = mysql_query($q) or die(mysql_error()); // Parādam datus while($row = mysql_fetch_array($result)) { echo "Spēles uzvarētas: ". $row[0]. ""; echo "<br />"; } 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 'Resource id #28' at line 1 Kas man mysql versija ir par vecu? o0 Edited December 9, 2007 by MārisL Link to comment Share on other sites More sharing options...
bubu Posted December 9, 2007 Report Share Posted December 9, 2007 Mums ar gaišreģību būtu jānodarbojas, lai uzzinātu tava izmantotā mysql versiju? Link to comment Share on other sites More sharing options...
andrisp Posted December 9, 2007 Report Share Posted December 9, 2007 Man gan liekas, ka tāds kverijs ir neiespējams. Vajag trīs atsevišūs kverijus: SELECT COUNT(*) FROM t WHERE rez1 > rez2; SELECT COUNT(*) FROM t WHERE rez1 = rez2; SELECT COUNT(*) FROM t WHERE rez1 < rez2; Link to comment Share on other sites More sharing options...
bubu Posted December 9, 2007 Report Share Posted December 9, 2007 Man gan liekas, ka ir gan, jo pats pamēģināju :) Link to comment Share on other sites More sharing options...
andrisp Posted December 9, 2007 Report Share Posted December 9, 2007 (edited) Ok, tūlīt arī pamēģināsu ;] Kas to būtu domājis - tiešām strādā... Edited December 9, 2007 by andrisp Link to comment Share on other sites More sharing options...
MārisL Posted December 9, 2007 Author Report Share Posted December 9, 2007 MySQL 4.1.11-Debian_4sarge7-log Link to comment Share on other sites More sharing options...
andrisp Posted December 9, 2007 Report Share Posted December 9, 2007 Tad pamēģini manu variantu ar trīs selektiem. Link to comment Share on other sites More sharing options...
MārisL Posted December 9, 2007 Author Report Share Posted December 9, 2007 (edited) Notice: Use of undefined constant zs - assumed 'zs' in /home/www/.../test.php on line 17 Šī ir viena no problēmām. un šī ir otra: paskatiju, ka man uzvarēto spēļu ir 37, bet viņš uzrāda tikai 31.. $uzvaretas_speles = mysql_query("SELECT COUNT(*) AS us FROM cw_rezultati WHERE rez1 > rez2"); $uzvaretas_speles = mysql_fetch_array($uzvaretas_speles); $uzvaretas_speles = $uzvaretas_speles[us]; $neizskirtas_speles = mysql_query("SELECT COUNT(*) AS ns FROM cw_rezultati WHERE rez1 = rez2"); $neizskirtas_speles = mysql_fetch_array($neizskirtas_speles); $neizskirtas_speles = $neizskirtas_speles[ns]; $zaudetas_speles = mysql_query("SELECT COUNT(*) AS zs FROM cw_rezultati WHERE rez1 < rez2"); $zaudetas_speles = mysql_fetch_array($zaudetas_speles); $zaudetas_speles = $zaudetas_speles[zs]; $kopa_speles = mysql_query("SELECT COUNT(*) AS ks FROM cw_rezultati"); $kopa_speles = mysql_fetch_array($kopa_speles); $kopa_speles = $kopa_speles[ks]; echo "<table>"; echo "<tr><td>Uzvarētas spēles:</td><td>".$uzvaretas_speles."</td></tr>"; echo "<tr><td>Zaudētas spēles:</td><td>".$zaudetas_speles."</td></tr>"; echo "<tr><td>Neizšķirtas spēles:</td><td>".$neizskirtas_speles."</td></tr>"; echo "<tr><td>Spēles kopā:</td><td>".$kopa_speles."</td></tr>"; echo "</table>"; :DDDDDD Viņš no uzvarētājām noņem 6 un pārliek zaudētājam. Zaudētājas rādas 27, bet vajadzētu būt 21 Edited December 9, 2007 by MārisL Link to comment Share on other sites More sharing options...
andrisp Posted December 9, 2007 Report Share Posted December 9, 2007 Tos undefined rāda jo, tev ir stringi bez pēdiņām: $uzvaretas_speles[us]; Link to comment Share on other sites More sharing options...
Recommended Posts