forSilence Posted October 13, 2010 Report Share Posted October 13, 2010 Uztaisīju video skriptu un tagad gribu uzlikt, lai rāda cik reizes skatīts. Tabulā izveidoju atsevišķu rowu views un ar query padevu, lai updeito viewus tabulā, bet kko esu izdarījis nepareizi, jo tabulā nekas neupdeitojas. Reku query's: $id = $_GET['id']; mysql_query ("UPDATE video SET views = views+1 WHERE id = $id"); Ceru uz jūsu palīdzību. Jau iepriekš, paldies. Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 13, 2010 Report Share Posted October 13, 2010 Ja otro rindiņu uzraksti: mysql_query ("UPDATE video SET views = views+1 WHERE id = $id") or die('Viss ir slikti: ' . mysql_error()); tad neko neizvada? Quote Link to comment Share on other sites More sharing options...
forSilence Posted October 13, 2010 Author Report Share Posted October 13, 2010 Ja otro rindiņu uzraksti: mysql_query ("UPDATE video SET views = views+1 WHERE id = $id") or die('Viss ir slikti: ' . mysql_error()); tad neko neizvada? Diemžēl nekādus errorus neizvada. Quote Link to comment Share on other sites More sharing options...
Vecteevs Posted October 13, 2010 Report Share Posted October 13, 2010 pamēģini tā: $query="UPDATE video SET views = views+1 WHERE id = $id" or die(mysql_error()); $rezultats=mysql_query($query); if($rezultats){ echo 'izdevaas'; } else { echo 'kluuda'; } Quote Link to comment Share on other sites More sharing options...
forSilence Posted October 13, 2010 Author Report Share Posted October 13, 2010 Viss strāda, nepareizā vietā biju viņu ielicis, bet kā sataisīt tā, lai skatījumus skaita tikai no vienas ip? Quote Link to comment Share on other sites More sharing options...
Vecteevs Posted October 13, 2010 Report Share Posted October 13, 2010 var ar vaicājumu piemēram $ip = $_SERVER['REMOTE_ADDR']; if($row['ip']==$ip){ echo 'IR IP'; } else { //iemetam DB } Quote Link to comment Share on other sites More sharing options...
werd Posted October 13, 2010 Report Share Posted October 13, 2010 (edited) Labākais risinājums būtu veidot atsevišķu tabulu, kurā būtu video ieraksta identifikators(video_id) un IP adrese(ip). MySQL vaicājums būtu attiecīgi: mysql_query("INSERT INTO video_views(video_id,ip) VALUES($id,$_SERVER['REMOTE_ADDR'])"); Pie video parādīšanas attiecīgi if vaicājums: $sql = mysql_query("SELECT * FROM video_views WHERE video_id = $id AND ip = $_SERVER['REMOTE_ADDR']"); if(!mysql_num_rows($sql)) { mysql_query("INSERT INTO video_views(video_id,ip) VALUES($id,$_SERVER['REMOTE_ADDR'])"); } Kopējo skatījumu skaitu noskaidrojam attiecīgi: $sql = mysql_query("SELECT * FROM video_views WHERE video_id = $id"); $views = mysql_num_rows($sql); P.S IP adrese nav labākais lietotāju identifikators, piemēram, Rīgas domes lietotāji būs vairāk kā 1000, bet IP adrese viena. Edited October 14, 2010 by werd Quote Link to comment Share on other sites More sharing options...
briedis Posted October 14, 2010 Report Share Posted October 14, 2010 (edited) werd - ļoti slikts un neefektīvs risinājums! Iedomājies, lai uzzinātu viena video skatījumus, db tiks prasīta VESELA TABULA ar datiem, tikai, lai uzzinātu viena video skatījumu skaitu. Tas nozīmē papildus slodzi db serverim, papildus bezjēdzīgu datu sūtīšana. forSilence, tavam variantam būtu jāstrādā. Kāds ir kolonnas datu tips? Nav kaut kāds varchar? Būtu jābūt (long) INT (un, vēlams unsigned) Edited October 14, 2010 by briedis Quote Link to comment Share on other sites More sharing options...
Kaklz Posted October 14, 2010 Report Share Posted October 14, 2010 Es STIPRI ieteiktu padomāt pie šīs konstrukcijas. Klasiska SQL injekcija. Padodot skripts.php?id=1 or 1 Tev pieskaitīsies skatījumi VISIEM VIDEO. $id = $_GET['id']; mysql_query ("UPDATE video SET views = views+1 WHERE id = $id"); Quote Link to comment Share on other sites More sharing options...
briedis Posted October 14, 2010 Report Share Posted October 14, 2010 Es STIPRI ieteiktu padomāt pie šīs konstrukcijas. Klasiska SQL injekcija. Padodot skripts.php?id=1 or 1 Tev pieskaitīsies skatījumi VISIEM VIDEO. $id = $_GET['id']; mysql_query ("UPDATE video SET views = views+1 WHERE id = $id"); ..un lieta atrisināta... $id = (int)$_GET['id']; mysql_query ("UPDATE video SET views = views+1 WHERE id = $id"); Quote Link to comment Share on other sites More sharing options...
forSilence Posted October 14, 2010 Author Report Share Posted October 14, 2010 Paldies Kaklz par aizrādījumu un paldies briedim, ka pateica kā to izlabot. Bet meigināju es, lai pieskaita vienu skatījmu tikai vienu reizi no vienas ip adreses, bet nekas nesanāca. Meigināju visu padot ar If'u, bet nekas nesanāca. Pieskaita skatījumus kā refrešo lapu, un neievada ip adreses un video id iekš db. Reku kods: $ip = quote_smart($_SERVER['REMOTE_ADDR']); if($row['ip'] != $ip){ mysql_query("UPDATE video SET views = views+1 WHERE id = {$_GET['id']} ") or die(mysql_error()); mysql_query("INSERT INTO video (ip,video_id) VALUES ($ip,{$_GET['id']} ) WHERE video_id = {$_GET['id']} "); } Quote Link to comment Share on other sites More sharing options...
Леший Posted October 14, 2010 Report Share Posted October 14, 2010 "INSERT INTO video (ip,video_id) VALUES ('$ip',{$_GET['id']} ) WHERE video_id = {$_GET['id']} " Pediņas Quote Link to comment Share on other sites More sharing options...
forSilence Posted October 14, 2010 Author Report Share Posted October 14, 2010 Nepalīdz :( Quote Link to comment Share on other sites More sharing options...
Леший Posted October 14, 2010 Report Share Posted October 14, 2010 if($row['ip'] != $ip){ No kurienes rodās tas $row ? Quote Link to comment Share on other sites More sharing options...
forSilence Posted October 14, 2010 Author Report Share Posted October 14, 2010 (edited) No query'a $result = mysql_query("SELECT * FROM video WHERE id = {$_GET['id']}"); while($row = mysql_fetch_assoc ($result)){ $ip = quote_smart($_SERVER['REMOTE_ADDR']); if($row['ip'] != $ip){ mysql_query("UPDATE video SET views = views+1 WHERE id = {$_GET['id']} ") or die(mysql_error()); mysql_query("INSERT INTO video (ip,video_id) VALUES ('$ip',{$_GET['id']} ) WHERE video_id = {$_GET['id']} "); } //te cits kods } Edited October 14, 2010 by forSilence 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.