smarty Posted August 3, 2005 Report Share Posted August 3, 2005 Sekojosha probleema - nepiecieshams atlasiit komenteeo bilzhu skaitu. it kaa vienkaarshi, bet ar mysql liidzekljiem nesanaak (pagaidaam atlasu visas grupeejot ar group by un saskaitot ar php liidzekljiem). taatad ir divas tabulas, no kuraam meegjinu atlasiit shaadi: SELECT count( c.photos_id ) AS total FROM photos AS p, comments AS c WHERE c.photos_id = p.photos_id bet tas atlasa pilniigi visus komentaarus. ja es ieliegu group by, tad atlasa katrai bildei komentaru skaitu, nevis kopeeju komenteeto bilzhu skaitu. varbuut tas nemaz nau iespeejams, kaa es iedomaajos? Link to comment Share on other sites More sharing options...
Delfins Posted August 3, 2005 Report Share Posted August 3, 2005 nu nafig tev JOINs ?! ... select count(*) from comments; Link to comment Share on other sites More sharing options...
bubu Posted August 3, 2005 Report Share Posted August 3, 2005 SELECT COUNT(photos_id) FROM comments Link to comment Share on other sites More sharing options...
Venom Posted August 3, 2005 Report Share Posted August 3, 2005 laikam tomēr SELECT COUNT(comment_id) FROM comments WHERE photo_id=[tekoši skatītās fotogrāfijas id] Link to comment Share on other sites More sharing options...
bubu Posted August 3, 2005 Report Share Posted August 3, 2005 Cik es sapratu no jautājuma - viņam vajag bilžu skaitu, kurām ir kaut viens komentārs. Link to comment Share on other sites More sharing options...
Delfins Posted August 3, 2005 Report Share Posted August 3, 2005 (edited) Cik es sapratu no jautājuma - viņam vajag bilžu skaitu, kurām ir kaut viens komentārs. 20232[/snapback] argh.. nepareizi sapratu... tad bubu, tavā variantā jālieto ir count(distinct(photos_id)) Edited August 3, 2005 by Delfins Link to comment Share on other sites More sharing options...
bubu Posted August 3, 2005 Report Share Posted August 3, 2005 (edited) Vai tad count(kolonna) neskaita unikālās vērtības? Edit: ā jā neskaita gan. Vajag tur distinct, kā Delfins saka. Edited August 3, 2005 by bubu Link to comment Share on other sites More sharing options...
smarty Posted August 3, 2005 Author Report Share Posted August 3, 2005 oo thanx! viss straada ar count(distinct(photos_id)) shaadu variantu biju palaidis garaam. Link to comment Share on other sites More sharing options...
Delfins Posted August 3, 2005 Report Share Posted August 3, 2005 shaadu variantu biju palaidis garaam. 20241[/snapback] iekš manuāļa ir.. zb jau šito atkārtot. Link to comment Share on other sites More sharing options...
Klez Posted August 6, 2005 Report Share Posted August 6, 2005 (edited) tad pie viena ... par count ... man taada lieta ... $all = "SELECT COUNT(`id`) FROM `tabula` WHERE `lauks` = 'vertiba' AND `lauks2` = 'vertiba2' LIMIT 100"; $one = mysql_fetch_row($all); echo $one[0]; // ~ 9000 atgreizh rezultaadu paaris tuukstoshus ~ 9000 $all = "SELECT * FROM `tabula` WHERE `lauks` = 'vertiba' AND `lauks2` = 'vertiba2' LIMIT 100"; $one = mysql_num_rows($all); echo $one[0]; // 100 manupraat COUNT tachu skaita ierakstus, cik atgriezh, vai arii es kljuudos ... Edited August 6, 2005 by Klez Link to comment Share on other sites More sharing options...
bubu Posted August 6, 2005 Report Share Posted August 6, 2005 (edited) Es atvainojos, bet ko tad citu tu tur gaidīji... $all = "SELECT * ... LIMIT 100";$one = mysql_num_rows($all); echo $one[0]; // 100 Būtu dīvaini, ja tas $one[0] būtu lielāks! A tas, ka tas COUNT(`id`) atgriež vairāk, tas taču loģiski, jo LIMIT darbojās pēc datu atlases, tb tev jau tikai 1 rindiņa tiek atgriezta (tas 9000), kas ir mazāks par 100 pieprasītajā. btw, tas laikam saīsināts pieraksts, ja? jo tur mysql_query() nekur neredzu.. Edited August 6, 2005 by bubu Link to comment Share on other sites More sharing options...
Klez Posted August 6, 2005 Report Share Posted August 6, 2005 mysql_query("SELECT COUNT(id) FROM tabula WHERE aluks_a > 10 AND lauks_a < 100 LIMIT 100"); taatad, sheit ir doma atlasiit ierakstus lapas raadiitaajam (Lapas: 1, 2, 3) ... var jau protams mysql_query("SELECT id FROM tabula WHERE aluks_a > 10 AND lauks_a < 100 LIMIT 100"); un tad mysql_num_rows bet manupraat COUNT ir aatraaks ... Link to comment Share on other sites More sharing options...
bubu Posted August 6, 2005 Report Share Posted August 6, 2005 Tu laikam nesaprati - LIMIT daļa izpildēs pēc rindu atlasīšanas, kas šajā gadījumā ir viena (1), jo SELECT COUNT(...) atgriež vienu rindu, ja netiek veikta grupēšana (GROUP BY) Link to comment Share on other sites More sharing options...
Klez Posted August 6, 2005 Report Share Posted August 6, 2005 (edited) sk :) bet ja buus select count(id) from tabula where lauks=12 tad tachu COUNT atgrieziis cik ir ieraxti ? vai nee Edited August 6, 2005 by Klez Link to comment Share on other sites More sharing options...
bubu Posted August 6, 2005 Report Share Posted August 6, 2005 Jā, tad count skaitīs tikai tos ierakstus, kuriem WHERE daļa būs true. Link to comment Share on other sites More sharing options...
Recommended Posts