euphoric Posted February 4, 2010 Report Share Posted February 4, 2010 Ir nepieciešams izvadīt vienā vietā pedējos ierakstus no 3 dažādam tabulām order by id desc, tas skaidrs, bet nevaru izfīčot pareizāko loģiku ,skriptam. Paldies . Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted February 4, 2010 Report Share Posted February 4, 2010 (edited) kodu paradi kas tev jau ir. $query = array(); $query[] = "select * from tabula1 order by id desc limit 0,5"; $query[] = "select * from tabula2 order by id desc limit 0,5"; $query[] = "select * from tabula3 order by id desc limit 0,5"; foreach($query as $q){ $q = mysql_query($q); while($array = mysql_fetch_array($q)){ $dati[] = $array; } } usort($dati); // masiva $dati ir 15 ieraksti protams ieteiktu tev lietot select ... left join ... Edited February 4, 2010 by EdgarsA Quote Link to comment Share on other sites More sharing options...
anonīms Posted February 4, 2010 Report Share Posted February 4, 2010 Varbūt par tādu metodi mani kāds sitīs, bet es izmantotu kaut ko tādu. $q = mysql_query("SELECT t1.pedejais1 as p1 FROM tabula1 AS t1, t2.pedejais2 as p2 FROM tabula2 as t2, t3.pedejais3 as p3 FROM tabula3 as t3") or die(mysql_error()); $data = mysql_fetch_assoc($q); un tad izvadi echo $data['p1']; echo $data['p2']; echo $data['p3']; Quote Link to comment Share on other sites More sharing options...
briedis Posted February 4, 2010 Report Share Posted February 4, 2010 google mysql UNION Quote Link to comment Share on other sites More sharing options...
2easy Posted February 4, 2010 Report Share Posted February 4, 2010 (edited) Varbūt par tādu metodi mani kāds sitīs, bet es izmantotu kaut ko tādu. $q = mysql_query("SELECT t1.pedejais1 as p1 FROM tabula1 AS t1, t2.pedejais2 as p2 FROM tabula2 as t2, t3.pedejais3 as p3 FROM tabula3 as t3") or die(mysql_error()); $data = mysql_fetch_assoc($q); labāk palasi, kā raksta sql SELECT http://dev.mysql.com/doc/refman/5.0/en/select.html Edited February 4, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
anonīms Posted February 4, 2010 Report Share Posted February 4, 2010 Vainīgs Pasen nebija nācies šādi rakstīt SELECT t1.*, t2.* FROM t1 INNER JOIN t2 ... Quote Link to comment Share on other sites More sharing options...
2easy Posted February 4, 2010 Report Share Posted February 4, 2010 (edited) Ir nepieciešams izvadīt vienā vietā pedējos ierakstus no 3 dažādam tabulām JOIN šajā gadījumā nederēs, pat ja tās 3x tabulas arī būtu savā starpā saistītas vai nu UNION vai 3x SELECT Edited February 4, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
euphoric Posted February 4, 2010 Author Report Share Posted February 4, 2010 Pāldies visiem , paeksperimentēšu :P Quote Link to comment Share on other sites More sharing options...
Gints Plivna Posted February 6, 2010 Report Share Posted February 6, 2010 JOIN šajā gadījumā nederēs, pat ja tās 3x tabulas arī būtu savā starpā saistītas vai nu UNION vai 3x SELECT Kāpēc ne, Dekarta reizinājums varētu derēt, ja visu vajag vienā ierakstā. Nu un, ja vajag 3, tad, protams UNION ALL. Gints Plivna http://datubazes.wordpress.com Quote Link to comment Share on other sites More sharing options...
2easy Posted February 6, 2010 Report Share Posted February 6, 2010 gadījumā dekarta reizinājums par daudz nesareizinās tās 3 savā starpā nesaistītās tabulas? Quote Link to comment Share on other sites More sharing options...
Gints Plivna Posted February 7, 2010 Report Share Posted February 7, 2010 Dekarta reizinājums dod visu ierakstu kombinācijas. Ja no katras tabulas ir pa 1 ierakstam, tad 1*1*1 vienalga ir 1. Ziepes, protams, potenciāli sākas tad, ja kādā no iesaistītajām tabulām atlasa vairāk kā 1, bet tad jebkurā gadījumā būtu kļūda. Gints Plivna http://datubazes.wordpress.com 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.