Lynx Posted March 11, 2005 Report Share Posted March 11, 2005 Tātad ideja ir šāda: Mēs izvelkam valstu nosaukumus no datubazes un pēc tam nosakam cik apmeklētāji bijuši no valstīm iekš db. $arz = mysql_query("SELECT valsts FROM apmekletaji WHERE valsts != 'LATVIA' AND valsts !='Nenosakāma' AND diena = '".$datums[2]."' AND menesis = '".$datums[1]."' AND gads = '".$datums[0]."' "); while ($row=mysql_fetch_array($arz)) { list($skaits) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM apmekletaji WHERE valsts = '".$row['valsts']."' AND diena = '".$datums[2]."' AND menesis = '".$datums[1]."' AND gads = '".$datums[0]."' ")); echo '<tr><td>'.$row['valsts'].'</td><td>'.$skaits.'</td><td></td></tr>'; } Un rezultāts izskatās aptuveni šāds: ESTONIA 2 ESTONIA 2 UNITED STATES 3 UNITED STATES 3 UNITED STATES 3 Kā uztaisīt, ka katrs valsts nosaukums un apmeklējumu skaits tiek izvadīts tikai vienu reizi? Link to comment Share on other sites More sharing options...
bubu Posted March 11, 2005 Report Share Posted March 11, 2005 $q = mysql_query("SELECT valsts, COUNT(valsts) FROM apmekletaji WHERE valsts != 'LATVIA' AND valsts !='Nenosakama' AND diena = '".$datums[2]."' AND menesis = '".$datums[1]."' AND gads = '".$datums[0]."' GROUP BY valsts"); while ($row=mysql_fetch_row($arz)) { echo '<tr><td>'.$row[0].'</td><td>'.$row[1].'</td><td></td></tr>'; } mysql_free_result($q); Link to comment Share on other sites More sharing options...
ohmygod Posted March 12, 2005 Report Share Posted March 12, 2005 (edited) hmz, BuBu, manupraat tavs variants arii izvadiis visus, kas atkaartojas, nevis tikai vienureizi. Sagrupeet vajag, bet + es dariitu taa, ka piešķirtu kkaadu mainiigo, ko pēc tam paarbaudīt vai neatkārtojas... $i=$row[1];//muusu mainiigajam pieshkjirma veertiibu no db shuunas if($i!=$j){echo $valsts} // mainiigajam $j veertiibu pieshkjirma veelaak, lai gadiijumaa, ja atškiras - zinātu, ka ir pienaacis atshkjiriigs ieraksts un ka tas jaaizvada. else{//varam iemest te teiksim, lai uzkaita, cik tieshi ir taadu ierakstu...} $j=$i; //domāju ka bez komentāriem... Edited March 12, 2005 by ohmygod Link to comment Share on other sites More sharing options...
Grey_Wolf Posted March 12, 2005 Report Share Posted March 12, 2005 (edited) hi hi :) vajag palasiit MYSQL manuaali :) un izmantot iespeejas ko sniedz mysql :) elementarna vatson: aiz select uzrakstam DISTINCT :) un viss ;) operaators SELECT peec savs buutibaas ir salikts operaators rakstot vienkaarshi SELECT - mysql saprot to kaa SELECT ALL :) (ALL - nokluseetaa veertiiba ) P.S. DISTINCT - neizvaadiis veertibas kas dubleejas :) Edited March 12, 2005 by Grey_Wolf Link to comment Share on other sites More sharing options...
bubu Posted March 12, 2005 Report Share Posted March 12, 2005 hmz, BuBu, manupraat tavs variants arii izvadiis visus, kas atkaartojas, nevis tikai vienureizi. 14937[/snapback] Acīmredzot, tu nezini ko dara GROUP BY keywords. Link to comment Share on other sites More sharing options...
bubu Posted March 12, 2005 Report Share Posted March 12, 2005 un izmantot iespeejas ko sniedz mysql :) elementarna vatson: aiz select uzrakstam DISTINCT :) un viss 14938[/snapback] Tieši tā kā tu saki - vajag "izmantot iespeejas ko sniedz mysql"! Tad kāpēc rakstīt n-tos kverijus (katru savai valstij), ja var visu informāciju iegūt vienā kverijā? Link to comment Share on other sites More sharing options...
ohmygod Posted March 12, 2005 Report Share Posted March 12, 2005 Acīmredzot, tu nezini ko dara GROUP BY keywords. 14942[/snapback] Es, protams, atvainojos, ka esmu duraks, bet man visu laiku likaas, ja ir kolonna "cipars" ar saturu katraa rindaa: 1;;3;1;4;1;2;5;1;3;2 Tad man ar parametru GROUP by cipars tiks izvadīts: 1;1;1;1;2;2;3;3;4;5 nevis 1;2;3;4;5 Tas maina izvadīšanas secību, nevis tikai unikālus ierakstus izvada! Palabo mani, ja kļudos, bet es visu laiku izmantoju šāda veida datu atlasi un nereizi man nav bijis tā, ka kaut ko neizvadītu tikai tamdēļ, ka ir jau izvadīts tāds pats ieraksts! Link to comment Share on other sites More sharing options...
tamster Posted March 12, 2005 Report Share Posted March 12, 2005 Es, protams, atvainojos, ka esmu duraks, bet man visu laiku likaas, ja ir kolonna "cipars" ar saturu katraa rindaa: 1;;3;1;4;1;2;5;1;3;2Tad man ar parametru GROUP by cipars tiks izvadīts: 1;1;1;1;2;2;3;3;4;5 nevis 1;2;3;4;5 14945[/snapback] Varbūt Tu jauc ar ORDER BY ? Link to comment Share on other sites More sharing options...
ohmygod Posted March 12, 2005 Report Share Posted March 12, 2005 (edited) Dziļi atvainojos :) Kkur pārķēru... ORDER ar GROUP... sorrz, bubu - nenjem ljaunaa... :unsure: Edited March 12, 2005 by ohmygod Link to comment Share on other sites More sharing options...
kirils Posted March 12, 2005 Report Share Posted March 12, 2005 kaapeec moderi nepaarbiida teemas zem pareizajiem apakshforumiem (php un db)? Link to comment Share on other sites More sharing options...
Kavacky Posted March 12, 2005 Report Share Posted March 12, 2005 kaapeec moderi nepaarbiida teemas zem pareizajiem apakshforumiem (php un db)?Gudrinieks. Link to comment Share on other sites More sharing options...
bubu Posted March 12, 2005 Report Share Posted March 12, 2005 Gudrinieks. 14958[/snapback] A bet kirilam taisnība tak! Moderi tam domāti - lai uzturētu kārtību forumā! Domā, ja kats sāks te ārdīties pēc savas patikas, visiem kļūs labāk? Link to comment Share on other sites More sharing options...
Kavacky Posted March 12, 2005 Report Share Posted March 12, 2005 Nekļūs vis, kārtību, protams, vajag. Tikai te tāds minimāls misēklis, kazi, moderators vēl nav pat apskatījies. Link to comment Share on other sites More sharing options...
Grey_Wolf Posted March 13, 2005 Report Share Posted March 13, 2005 Nekļūs vis, kārtību, protams, vajag. Tikai te tāds minimāls misēklis, kazi, moderators vēl nav pat apskatījies. 14961[/snapback] Mjaa... es arii uz reiz neieveeroju .... nu gan ka skiet uz Of topiku :) :) Link to comment Share on other sites More sharing options...
Klez Posted March 14, 2005 Report Share Posted March 14, 2005 (edited) $arz = mysql_query("SELECT DISTINCT(valsts) FROM apmekletaji WHERE valsts != 'LATVIA' AND valsts !='Nenosakāma' AND diena = '".$datums[2]."' AND menesis = '".$datums[1]."' AND gads = '".$datums[0]."' "); while ($row=mysql_fetch_array($arz)) { list($skaits) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM apmekletaji WHERE valsts = '".$row['valsts']."' AND diena = '".$datums[2]."' AND menesis = '".$datums[1]."' AND gads = '".$datums[0]."' ")); echo '<tr><td>'.$row['valsts'].'</td><td>'.$skaits.'</td><td></td></tr>'; } pameegini sho te. valstiim nevaidzeetu atkaartoties Edited March 14, 2005 by Klez Link to comment Share on other sites More sharing options...
Recommended Posts