anonīms Posted January 31, 2009 Report Share Posted January 31, 2009 <?php $pedejie_rezultati = mysql_query("SELECT id, valsts, pretinieks, km1_rez, km2_rez FROM ".DB_PREFIX."cw_rezultati ORDER BY id DESC LIMIT 5"); while($pr = mysql_fetch_array($pedejie_rezultati)) { if($pr['km1_rez'] > $pr['km2_rez']) { $krasa = 'green'; } elseif($pr['km1_rez'] == $pr['km2_rez']) { $krasa = 'blue'; } else { $krasa = 'red'; } echo '<li><a href="?sadala=cw_rezultati&id='.$pr['id'].'">'.$settings['komandas_tags'].' vs <img src="images/flags/'.$pr['valsts'].'.gif" alt="" /> '.$pr['pretinieks'].'</a> <span style="color:'.$krasa.'; font-weight:bold;">'.$pr['km1_rez'].':'.$pr['km2_rez'].'</span></li>'; } $count_rez = mysql_query("SELECT count(id) FROM ".DB_PREFIX."cw_rezultati"); $count_rez = mysql_fetch_array($count_rez); if($count_rez[0] < 1) { echo "<li>Pagaidām vēl nav noticis neviens cw...</li>"; } ?> Kā šos abus varētu apvienot vienā? Link to comment Share on other sites More sharing options...
bubu Posted January 31, 2009 Report Share Posted January 31, 2009 Neredzu kāpēc tie būtu jāapvieno vienā. Tas otrs kverijs ir pilnīgi neatkarīgs no pirmā - tas tikai saskaita ierakstu skaitu (ja id tev ir unikāls). Iznes vienkārši to otro kveriju no while cikla ārā, un iekšā atstāj jau iepriekš izvilkto datu izvadīšanu. Link to comment Share on other sites More sharing options...
rausis Posted January 31, 2009 Report Share Posted January 31, 2009 tas otrs kverijs nemaz nav ciklā, var darīt kkā tā: <?php $pedejie_rezultati = mysql_query("SELECT COUNT(id) AS count, id, valsts, pretinieks, km1_rez, km2_rez FROM ".DB_PREFIX."cw_rezultati ORDER BY id DESC LIMIT 5"); while($pr = mysql_fetch_array($pedejie_rezultati)) { if($pr['km1_rez'] > $pr['km2_rez']) { $krasa = 'green'; } elseif($pr['km1_rez'] == $pr['km2_rez']) { $krasa = 'blue'; } else { $krasa = 'red'; } echo '<li><a href="?sadala=cw_rezultati&id='.$pr['id'].'">'.$settings['komandas_tags'].' vs <img src="images/flags/'.$pr['valsts'].'.gif" alt="" /> '.$pr['pretinieks'].'</a> <span style="color:'.$krasa.'; font-weight:bold;">'.$pr['km1_rez'].':'.$pr['km2_rez'].'</span></li>'; } $cnt = mysql_fetch_row($pedejie_rezultati); if($cnt[0] < 1) { echo "<li>Pagaidām vēl nav noticis neviens cw...</li>"; } ?> var izmantot arī mysql_num_rows()... Link to comment Share on other sites More sharing options...
bubu Posted January 31, 2009 Report Share Posted January 31, 2009 tas otrs kverijs nemaz nav ciklā Taisnība :) Pārskatījos. Tā ir, ka kodā nav normāli atkāpes saliktas. Link to comment Share on other sites More sharing options...
Recommended Posts