sandis_m Posted August 20, 2010 Report Share Posted August 20, 2010 users uid | name | lastname | profilepic comments sid | author | time | text comments_likes wid | wsid | wautors SQL: $whatsnew_sql = mysql_query(" SELECT comm.*, u.uid,`name`,`lastname`,`profilepic`, coommlk.* FROM `comments` comm, `users` u, `comments_likes` commlk WHERE comm.author = u.uid ORDER BY `comm.sid` DESC LIMIT 12 "); Rezultātā vajadzētu izvadīt komentārus un ja tabulā `comments_likes` `wid` ir vienāds ar `comments` `sid` tad vajadzēja parādīties sirsniņai. Bet nez kkas tur nav kā vajag Quote Link to comment Share on other sites More sharing options...
codez Posted August 20, 2010 Report Share Posted August 20, 2010 ieteiktu tabulām kā primary_key likt id, nevis xid, jo piemēram uid būtu saīsinājums no userid, bet pie tā lauka tu griezies ar users.uid. Sanāk, ka 2 reizes lieto user. Un vispār id lietot kā primary_key, kur tā ir viena, ir tākā nedaudz standarts. Par tēmu, tev vajag LEFT JOIN un tad, ja nebūs atbilstoša comments_like ieraksta, tajā vietā būs NULL. Quote Link to comment Share on other sites More sharing options...
sandis_m Posted August 20, 2010 Author Report Share Posted August 20, 2010 Tātad, tam vajadzētu izskatīties šādi?: $whatsnew_sql = mysql_query(" SELECT comm.*, u.uid,`name`,`lastname`,`profilepic` FROM `comments` comm, `users` u LEFT JOIN `comments_likes` WHERE comm.author = u.uid ORDER BY `comm.sid` DESC LIMIT 12 "); bet kkas nesanāk ;/ Quote Link to comment Share on other sites More sharing options...
briedis Posted August 20, 2010 Report Share Posted August 20, 2010 (edited) Palasi manuāli, kā raksta LEFT JOIN. Ir tāda jauka adresīte - google. Un tur kur atlasi kolonnas, pareizais stils būtu norādīt, kura kolonna tad jāņem no kuras tabulas - tabula.lauks Edited August 20, 2010 by briedis Quote Link to comment Share on other sites More sharing options...
sandis_m Posted August 20, 2010 Author Report Share Posted August 20, 2010 Palasi manuāli, kā raksta LEFT JOIN. Ir tāda jauka adresīte - google. ā .tad sanāk visas tabulas ar left join? Quote Link to comment Share on other sites More sharing options...
codez Posted August 20, 2010 Report Share Posted August 20, 2010 (edited) nē, var to vienu, tev tikai trūkst ON un nosacījums ar kuru joinot - skaties dokomentāciju. Edited August 20, 2010 by codez Quote Link to comment Share on other sites More sharing options...
bubu Posted August 20, 2010 Report Share Posted August 20, 2010 Vai arī ar RIGHT JOIN, vai INNER JOIN, vai CROSS JOIN, utt. Lasi: http://datubazes.wordpress.com/2008/02/11/sql-join-i/ Quote Link to comment Share on other sites More sharing options...
sandis_m Posted August 20, 2010 Author Report Share Posted August 20, 2010 Vēl īsti netieku skaidrībā. Quote Link to comment Share on other sites More sharing options...
briedis Posted August 20, 2010 Report Share Posted August 20, 2010 Tiešām nevari izzīst no šī piemēra? http://www.w3schools.com/sql/sql_join_left.asp 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.