anonīms Posted March 18, 2008 Report Share Posted March 18, 2008 (edited) Lieta tāda, ka ir skripts 'Jaunākais forumā' $jaunakas_atb = mysql_query ("SELECT id, autors, teksts, topika_id, kategorijas_id FROM forums_atbildes ORDER BY id DESC LIMIT 5"); while($pedatbildes = mysql_fetch_array($jaunakas_atb)) { ................ } bet sanāk tā, ka viņš tagad ņem atbildes, bet vēlos arī, lai tiktu ņemti dati no tabulas forums_topiki un tad oder by datums desc. To var panākt ar JOIN vai UNION? Un ja varētu, tad vēl mazu piemēru lūgums.. Edited March 18, 2008 by anonīms Link to comment Share on other sites More sharing options...
Vebers Posted March 18, 2008 Report Share Posted March 18, 2008 SELECT fa.id, fa.autors, fa.teksts, fa.topika_id, fa.kategorijas_id, ft.title FROM forums_atbildes fa left join foruma_topiki ft on ft.id = fa.topika_id ORDER BY fa.id DESC LIMIT 5 Link to comment Share on other sites More sharing options...
anonīms Posted March 18, 2008 Author Report Share Posted March 18, 2008 $jaunakas_atb = mysql_query ("SELECT fa.id, fa.autors, fa.teksts, fa.topika_id, fa.kategorijas_id FROM forums_atbildes fa left join forums_topiki ft on ft.id = fa.kategorijas_id ORDER BY fa.id DESC LIMIT 5") or die(mysql_error()); uztaisot print_r, rādas tikai dati, ko izvelk no forums_atbildes Array ( [0] => 126 [id] => 126 [1] => aLT [autors] => aLT [2] => english coming soon [teksts] => english coming soon [3] => 34 [topika_id] => 34 [4] => 2 [kategorijas_id] => 2 ) Link to comment Share on other sites More sharing options...
Vebers Posted March 18, 2008 Report Share Posted March 18, 2008 Tapēc, ka no izvelc datus tikai no forums_atbildes (fa) tabulas. Skaties daļu no Select līdz From. Tur pievieno ko vien vēlies no forums_topiki (ft) tabulas. Piemēram ft.topic_title Link to comment Share on other sites More sharing options...
anonīms Posted March 18, 2008 Author Report Share Posted March 18, 2008 $jaunakas_atb = mysql_query ("SELECT fa.id, fa.autors, fa.teksts, fa.topika_id, fa.kategorijas_id FROM forums_atbildes fa left join forums_topiki ft on ft.kategorijas_id, ft.autors, ft.nosaukums, ft.kategorijas_id = fa.kategorijas_id ORDER BY fa.id DESC LIMIT 5") or die(mysql_error()); izlec errors par sintaksi. Link to comment Share on other sites More sharing options...
Vebers Posted March 18, 2008 Report Share Posted March 18, 2008 (edited) A kāpēc uzreiz bāz to visu uzreiz aiz left join on [tavi lauki] ? Ja viņiem ir jābūt uzreiz aiz Select un pirms From ? SELECT fa.id, fa.autors, fa.teksts, fa.topika_id, fa.kategorijas_id, ft.autors, ft.nosaukums, ft.kategorijas_id FROM forums_atbildes fa left join forums_topiki ft on ft.kategorijas_id = fa.kategorijas_id ORDER BY fa.id DESC LIMIT 5 Edited March 18, 2008 by Vebers Link to comment Share on other sites More sharing options...
anonīms Posted March 18, 2008 Author Report Share Posted March 18, 2008 $jaunakas_atb = mysql_query ("SELECT fa.id, fa.autors, fa.teksts, fa.topika_id, fa.kategorijas_id, fa.laiks, ft.autors, ft.kategorijas_id, ft.laiks FROM forums_atbildes fa left join forums_topiki ft on ft.laiks = fa.laiks ORDER BY fa.laiks DESC LIMIT 5 ") or die(mysql_error()); bet lauki no ft rādas tukši Array ( [0] => 126 [id] => 126 [1] => aLT [autors] => [2] => english coming soon [teksts] => english coming soon [3] => 34 [topika_id] => 34 [4] => 2 [kategorijas_id] => [5] => 1205771929 [laiks] => [6] => [7] => [8] => ) Link to comment Share on other sites More sharing options...
Vebers Posted March 18, 2008 Report Share Posted March 18, 2008 UZ lauku joinot ir vienkaarsi stulbi :) Tapec ka viena sekundee var but dafigaa jauni posti. pec topika id joino! Link to comment Share on other sites More sharing options...
anonīms Posted March 19, 2008 Author Report Share Posted March 19, 2008 (edited) $testee = mysql_query("SELECT * FROM forums_topiki LEFT JOIN forums_atbildes ON forums_atbildes.laiks=forums_topiki.laiks ORDER BY forums_topiki.laiks DESC LIMIT 5 ") or die(mysql_error()); $testee = mysql_fetch_array($testee); print_r($testee); Vot kādēļ viņš neizvelk datus no forums_atbildes tagad? * - visu taču vajadzētu Edited March 19, 2008 by anonīms Link to comment Share on other sites More sharing options...
Recommended Posts