anonīms Posted February 24, 2008 Report Share Posted February 24, 2008 Vēlos apvienot vienā vietā, kur man ir "Jaunākie komentāri" komentārus no divām tabulām. tb - komentari un video_komentari. Zinu, ka vajag izmantot JOIN, bet vai nevarētu kaut cik sīkāk paskaidrot kā īsti veidot? $jaunakie_kom = mysql_query ("SELECT niks, komentars, j FROM komentari ORDER BY id DESC LIMIT 5"); Link to comment Share on other sites More sharing options...
bubu Posted February 24, 2008 Report Share Posted February 24, 2008 Īsti nesapratu, bet nu pieņemsim, ka šitā: SELECT komentari.niks, komentari.koments, video_komentari.koments FROM komentari JOIN video_komentari ON komentari.id = video_komentari.komenta_id Link to comment Share on other sites More sharing options...
anonīms Posted February 24, 2008 Author Report Share Posted February 24, 2008 $jaun = mysql_query ("SELECT komentari.niks, komentari.komentars, video_komentari.komentars FROM komentari JOIN video_komentari ON komentari.id = video_komentari.id ORDER BY laiks DESC LIMIT 5"); Kas šeit ir nepareizs? Link to comment Share on other sites More sharing options...
Aleksejs Posted February 24, 2008 Report Share Posted February 24, 2008 Un kādēļ Tev šķiet, ka tur ir kaut kas nepareizs? Link to comment Share on other sites More sharing options...
anonīms Posted February 24, 2008 Author Report Share Posted February 24, 2008 Tādēļ, ka man neizvada datus. $jaun = mysql_query("SELECT komentari.niks, komentari.komentars, video_komentari.komentars FROM komentari JOIN video_komentari ON komentari.id = video_komentari.id ORDER BY datums DESC LIMIT 5"); while($pedkom = mysql_fetch_array($jaun)) { echo "<li>".ShortenText($pedkom['0'].", <a href='http://.../jaunums/$pedkom[2]'>".$pedkom['1'])."</a></li>"; } Link to comment Share on other sites More sharing options...
bubu Posted February 24, 2008 Report Share Posted February 24, 2008 Droši vien datu nav - selekts neatgrieza nevienu ierakstu. Paņem izpildi kveriju mysql konsolē, pamaini to, paeksperimentē. Citādi neviens tev nevarēs palīdzēt (kristāla bumbas visi ebayā pārdevuši). Link to comment Share on other sites More sharing options...
Val Posted February 24, 2008 Report Share Posted February 24, 2008 http://lv.php.net/mysql_error http://lv.php.net/error_reporting Link to comment Share on other sites More sharing options...
anonīms Posted February 24, 2008 Author Report Share Posted February 24, 2008 #1052 - Column 'datums' in order clause is ambiguous datums vietā ierakstu id - ar tas pats izmetas. tabulā datuma kollona ir! Link to comment Share on other sites More sharing options...
bubu Posted February 24, 2008 Report Share Posted February 24, 2008 Viņš jau nesūdzās, ka tāda kolonna nav. "ambiguous" nozīmē neviennozīmību. Tas nozīmē, ka tā kolonna "datums" ir vairākās tabulās un MySQL nezin, no kuras tabulas tu to gribi ņemt. Raksti tabulas_nosaukums.datums Link to comment Share on other sites More sharing options...
anonīms Posted February 25, 2008 Author Report Share Posted February 25, 2008 bet, ja man ir vajadzīgi datumu no abām tabulām, lai sagrupēt kopēji pēc jaunākā? Link to comment Share on other sites More sharing options...
Aleksejs Posted February 25, 2008 Report Share Posted February 25, 2008 Parādi abu tabulu struktūru. Link to comment Share on other sites More sharing options...
anonīms Posted February 25, 2008 Author Report Share Posted February 25, 2008 tabula komentari id, j, niks, komentars, datums tabula video_komentari id, video, niks, komentars, datums j un video ir jaunuma_id un video_id Link to comment Share on other sites More sharing options...
Delfins Posted February 25, 2008 Report Share Posted February 25, 2008 1.) izmano AS x_datums un AS y_datums 2.) order by x_datums, y_datums Link to comment Share on other sites More sharing options...
bubu Posted February 25, 2008 Report Share Posted February 25, 2008 Tev drīzak tur UNION vajag, nevis JOIN. Link to comment Share on other sites More sharing options...
Aleksejs Posted February 25, 2008 Report Share Posted February 25, 2008 SELECT id, j AS kid, niks, komentars, datums, 1 AS tips FROM komentari UNION ALL SELECT id, video AS kid, niks, komentars, datums, 2 AS tips FROM video_komentari ORDER BY datums un pēc lauka tips nosaki, vai tas ir video komentārs, vai nē. Link to comment Share on other sites More sharing options...
Recommended Posts