Pentiums Posted July 22, 2008 Report Share Posted July 22, 2008 Jautājums par vienreizēju datu uzskaitīšanu... Tātad ir counter skripta tabula ip adresēm.. kā lai uzskaita unikālos apmeklējumus? piemēram šeit unikālie apmeklējumi būtu 3 23.153.213.232 23.153.213.232 198.34.231.111 23.153.213.232 127.0.0.1 23.153.213.232 198.34.231.111 23.153.213.232 Link to comment Share on other sites More sharing options...
Gints Plivna Posted July 22, 2008 Report Share Posted July 22, 2008 SELECT count(distinct <kolona>) FROM <tabula> Gints Plivna http://datubazes.wordpress.com Link to comment Share on other sites More sharing options...
andrisp Posted July 22, 2008 Report Share Posted July 22, 2008 Gint, tā kā 99% gadījumos tu postē SQL, tad gribēju tav atgādīnat par SQL bbcode tagu. ;) Link to comment Share on other sites More sharing options...
Gints Plivna Posted July 22, 2008 Report Share Posted July 22, 2008 Ummm gribi teikt, ka bija speciāls SQL tags :O SELECT count(distinct kolona) FROM tabula Hmm tiešām Biju kaut kā piemirsis vai arī nekad nebiju īsti pamanījis ;) Garākus tekstus parasti liku viekārši iekš code... Gints Plivna http://datubazes.wordpress.com Link to comment Share on other sites More sharing options...
Pentiums Posted July 22, 2008 Author Report Share Posted July 22, 2008 liels paldies!!!!!!! :))) Link to comment Share on other sites More sharing options...
Klez Posted July 22, 2008 Report Share Posted July 22, 2008 (edited) man liekas ka efektiivaak tavu tabulu buutu mazliet paarveidot .... tabula: id - ip - datums - skaits un fcija function statistika($ip) { $dat = date("Y.m.d"); $all = mysql_query("SELECT id FROM tabula WHERE ip = '$ip' AND datums = '$dat'"); if (mysql_num_rows($all) == 0) mysql_query("INSERT INTO tabula (ip,datums,skaits) VALUES ('$ip','$dat',1)"); else { $one = mysql_fetch_row($all); mysql_query("UPDATE tabula SET skaits = skaits + 1 WHERE id = ".$one[0]); } mysql_free_result($all); } aptuveni shitaa, un buus tev arii kaut kaads arhiivs :) datumu vari glabaat arii kaa int, tipa mktime($dat) .. taa ir gaumes lieta ... un tad jau unikaalos var dabuut: SELECT skaits FROM tabula where ip=$ip and datums = 'šodien' mazaak tabulaa vietu aiznjem un aatraak straadaas. + indeksi pareizajaas vietaas ;) Edited July 22, 2008 by Klez Link to comment Share on other sites More sharing options...
Pentiums Posted July 22, 2008 Author Report Share Posted July 22, 2008 paldies es to pats arī jau izdarīju, man tikai vajadzēja uzzināt konkrēto SQL funkciju Link to comment Share on other sites More sharing options...
Paulinjsh Posted July 22, 2008 Report Share Posted July 22, 2008 vispar klez rakstīto var pārrakstīt savādāk: mysql_query("INSERT INTO tabula (ip,datums,skaits) VALUES ('$ip','$dat',1) ON DUPLICATE KEY UPDATE skaits = skaits + 1"); Link to comment Share on other sites More sharing options...
marrtins Posted July 23, 2008 Report Share Posted July 23, 2008 Un protams, ip lauks kā type int (tiesa gan, nedarbosies ip6, bet, šķiet, ka tas šeit nav vajadzīgs) un insert into bla bla (ip) values (inet_ntoa('127.0.0.1')) - mazāk vietas aizņems (būs ātrāks). Indekss uz ip un visi dati atmiņā (protams, ja RAMs pietiekami), bet četri baiti uz vienu ip ir daudz labāk kā varcharam (min 7 max 15) Link to comment Share on other sites More sharing options...
Grey_Wolf Posted July 23, 2008 Report Share Posted July 23, 2008 Un protams, ip lauks kā type int (tiesa gan, nedarbosies ip6, bet, šķiet, ka tas šeit nav vajadzīgs) lai buutu ar IP6 var izmantot BigInt .... Bet IP tik tiesam jaglabaa kaa INT .. --- Conterim var veidot 2 DB laukus .. ip (INT) Primary Key UNIQUE | skaits (int) ... (saja gadijumaa var iztikt bez id , jo pati IP jau kalpos kaa primaaraa atsleega .....) peec tam parbaudiit vai saada IP jau nav ja ir tad skaits=skaits+1 ..... dabuusi gan Unikalos, gan cik no katras IP ir bijusi apmeklejumi.... Link to comment Share on other sites More sharing options...
Recommended Posts