anonīms Posted April 14, 2010 Report Share Posted April 14, 2010 (edited) $last_matches = query("SELECT * FROM ".PREFIX."speles WHERE izspelets = '1' ORDER BY id DESC LIMIT 5"); while($lm = mysql_fetch_assoc($last_matches)) { $km1 = mysql_fetch_assoc(query("SELECT id, nosaukums, logo FROM ".PREFIX."komandas WHERE id = '".$lm['komanda1']."'")); $km2 = mysql_fetch_assoc(query("SELECT id, nosaukums, logo FROM ".PREFIX."komandas WHERE id = '".$lm['komanda2']."'")); } Kā varētu šos kverijus apvienot vienā? tb nahrenizēt $km1,$km2. ja teiksim vajadzētu tikai km1, tad viss mierīgi, bet šādi... Edited April 14, 2010 by anonīms Quote Link to comment Share on other sites More sharing options...
Kaklz Posted April 14, 2010 Report Share Posted April 14, 2010 $last_matches = query("SELECT * FROM ".PREFIX."speles WHERE izspelets = '1' ORDER BY id DESC LIMIT 5"); while($lm = mysql_fetch_assoc($last_matches)) { $qry = 'select id, nosaukums, logo from '. PREFIX. 'komandas where id in ('. $lm['komanda1'] . ',' . $lm['komanda2'] . ')'; $r = mysql_query($qry); $i = 1; while($row = mysql_fetch_assoc($r)){ $km[$i++] = $row; } } Tik cik tu griezīsies nevis pie $km1, $km2, bet pie $km[1] vai $km[2]. Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted April 14, 2010 Report Share Posted April 14, 2010 Kaut kā tā.. SELECT s.komanda1 AS k1_id,s.komanda2 AS k2_id,k1.nosaukums AS k1_nosaukums,k2.nosaukums AS k2_nosaukums,k1.logo AS k1_logo, k2.logo AS k2_logo FROM ".PREFIX."speles AS s JOIN ".PREFIX."komandas AS k1 ON s.komanda1=k1.id JOIN ".PREFIX."komandas AS k2 ON s.komanda2=k2.id WHERE s.izspelets = '1' ORDER BY id DESC LIMIT 5 Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 14, 2010 Author Report Share Posted April 14, 2010 (edited) Kaklz kko pārprati :D xPtv45z, thx. Došu ziņu, ja kkas nefunkcionēs EDIT: Column 'id' in order clause is ambiguous EDIT2: Njā, ok :D ORDER BY s.id DESC LIMIT 5 Pagaidām iet nevainojami Edited April 14, 2010 by anonīms Quote Link to comment Share on other sites More sharing options...
Kaklz Posted April 14, 2010 Report Share Posted April 14, 2010 Kāds jautājums, tāda atbilde :) Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 15, 2010 Author Report Share Posted April 15, 2010 NEXT ONE http://paste.php.lv/33ee66a0451ba355e26c0d12b11fae1f?lang=php Doma galvā ir, bet praktiski to izmantot nespēju. Teiksim to visu apvienot zem viena kā query("(select 1) AS uzvaras, (select 2) AS zuades, (select 3) AS neizskirti"); Bet vjaadzīga tak atkal tabula, etc. Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted April 15, 2010 Report Share Posted April 15, 2010 (edited) Nevajag obligāti FROM, ja pareizi sapratu tevi. Arī šāds strādās - "SELECT 'hello world' as hello" Vienīgi tevis norādītajos, var nestrādāt tā kā tu gribi dēļ and un or sakombinējuma, ieteiktu rakstīt šādi WHERE ((komanda1 = '".$team['id']."' AND km1_rez > km2_rez) OR (komanda2 = '".$team['id']."' AND km1_rez < km2_rez)) AND izspelets = '1' To var dabūt arī savādāk, vienīgi te būs nepieciešami divi selecti, kā bez subselectiem apvienot vienā īsti nezinu, bet domāju, ka šiem vajadzētu darboties ātrāk, nekā iepriekšējam ar daudzajiem subselectiem. "SELECT SUM(IF(km1_rez>km2_rez,1,0)) as uzvaras, SUM(IF(km1_rez=km2_rez,1,0)) as neizskirts,SUM(IF(km1_rez<km2_rez,1,0)) as zaudejums FROM ".PREFIX."speles WHERE komanda1 = '".$team['id']."' izspelets = '1'" "SELECT SUM(IF(km1_rez<km2_rez,1,0)) as uzvaras, SUM(IF(km1_rez=km2_rez,1,0)) as neizskirts,SUM(IF(km1_rez>km2_rez,1,0)) as zaudejums FROM ".PREFIX."speles WHERE komanda2 = '".$team['id']."' izspelets = '1'" Var mēgināt pārbaudīt vai IF funkcija atbalsta vairākus nosacījumus IF((komanda1=$team['id'] AND km_1>km_2) OR (komanda2=$team['id'] AND km_1<km_2),1,0) Edited April 15, 2010 by xPtv45z Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 15, 2010 Author Report Share Posted April 15, 2010 Ok, izmantošu tos 2 vaicājumus. Vēl kas... http://paste.php.lv/02c5fcbe7f73ac545f9b0f2c443a7c46?lang=php Vai ir iespēja kaut kā šos 3 kverijus apvienot vienā? (foreach) ar domu, ja pēc katras pozīcijas beigām ir echo '<tr><th colspan="5">'.$sastavs_title[$v].'</th></tr>'; ? Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted April 15, 2010 Report Share Posted April 15, 2010 (edited) $SQL = query("SELECT id, vards, ddiena, numurs, pozicija FROM ".PREFIX."speletaji WHERE pozicija in (".implode(',',array_keys($sastavs)).") AND komanda = '".intval($_GET['id'])."' ORDER BY pozicija ASC"); if(mysql_num_rows($SQL) > 0){ $currPozicija=null; while($PLR = mysql_fetch_assoc($SQL)){ if($currPozicija!=$PLR['pozicija']){ if($currPozicija){ echo "<tr><td></td><td><span style='color: #ff0000;'>Komandai nav pieteikts neviens ".$sastavs[$currPozicija]."...</span></td></tr>"; } $currPozicija=$PLR['pozicija']; echo '<tr><th colspan="5">'.$sastavs_title[$currPozicija].'</th></tr>'; } if($PLR['numurs'] == 0) $PLR['numurs'] = 0; echo '<tr><td>#'.$PLR['numurs'].'</td><td><a href="?sadala=statistika&id='.$PLR['id'].'">'.$PLR['vards'].'</a></td><td>'.$PLR['ddiena'].'</td></tr>'; } echo "<tr><td></td><td><span style='color: #ff0000;'>Komandai nav pieteikts neviens ".$sastavs[$currPozicija]."...</span></td></tr>"; } Edited April 15, 2010 by xPtv45z Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 16, 2010 Author Report Share Posted April 16, 2010 (edited) +/- strādā, bet ir tā, ka, ja komandām nav neviens spēlētājs pieteikts, tad vispār nerāda to tabulu (arī noņemot num_rows > 1) Un vēl, ja nav teiksim vārtusargs komandā, tad arī nerāda, ne <th>, ne arī var izvilkt sastava title, jo tāds (3 pozicija) vnk neizvadās (+ izmet augšā) kr4 te ir tavs kods darbībā - http://bliezam.lv/public/vhl/?sadala=komandas&id=1 + echo $currPozicija.":".$PLR['pozicija']; Edited April 16, 2010 by anonīms Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted April 16, 2010 Report Share Posted April 16, 2010 Tad viss ir jāpārtaisa, bet man slinkums rakstīt. Ideja ir tāda, ka, lai paliek foreach kā iepriekš, bet ar šo sql pirms foreach izvelc nepieciešamos info un sagatavo masīvu ar datiem. Es veidotu kaut kā tā $data=array(1=>array(atlasīto ierakstu masīvs ar uzbrucējiem),2=>array(atlasīto ierakstu masīvs ar aizsargiem), utt); Pēc tam iekš foreach, tev atliek tikai iziet ar ciklu nepieciešamajam cauri - $data[$pozicija] un izdrukāt. Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 16, 2010 Author Report Share Posted April 16, 2010 (edited) ok, mēģināšu em. vispār es īsti nesapratu. Varbūt vari mazu piemēru. Gribēju pamēģināt tā, ka teiksim ir viens vaicājums un ar ifiem, bet kā nosaka while($PLR = $SQL) tad nākamos while vairs nevar izmanto $SQL = query("SELECT id, vards, ddiena, numurs, pozicija FROM ".PREFIX."speletaji WHERE komanda = '".intval($_GET['id'])."' ORDER BY pozicija ASC"); foreach($sastavs AS $v=>$t) { echo '<tr><th colspan="5">'.$sastavs_title[$v].'</th></tr>'; while($PLR = mysql_fetch_assoc($SQL)) { if($PLR['pozicija'] == $v) { echo '<tr><td>#'.$PLR['numurs'].'</td><td><a href="?sadala=statistika&id='.$PLR['id'].'">'.$PLR['vards'].'</a></td><td>'.$PLR['ddiena'].'</td></tr>'; } } } Edited April 16, 2010 by anonīms Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted April 16, 2010 Report Share Posted April 16, 2010 (edited) Nē. Apmēram šādi. $data=array(); $sql=.. while(){ $data[$PLR['pozicija']][]=$PLR; } foreach($sastavs as $v=>$t){ foreach($data[$v] as $PLR){//tagad $PLR saturēs visu to pašu ko iepriekš - atsevišķus ierastus no db ar atbilstošajām pozicijām } } Edited April 16, 2010 by xPtv45z Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 16, 2010 Author Report Share Posted April 16, 2010 O, thx. Beidzot dabūjām gatavu :D http://paste.php.lv/01a8f44682cc61ec1e4835a01f0c65c5?lang=php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.