brown2005 Posted March 9, 2006 Share Posted March 9, 2006 hi,i have if ($_GET['id']) {$sq1 = "SELECT * FROM ads_hits WHERE hits = '".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."'";$r1 = mysql_query($sq1) or die(mysql_error());$sql2 ="UPDATE ads_hits SET hits_count= hits_count +1 WHERE hits='".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."' ";$updated=true;mysql_query($sql2);echo FINISHED;exit();}and this adds one to the count, but now i want to be able to say if the ip and id have not had a hit then it will add the ip and id to the database and if it has 1 hit or more then it runs the query above... Link to comment https://forums.phpfreaks.com/topic/4556-count-from-database/ Share on other sites More sharing options...
obsidian Posted March 9, 2006 Share Posted March 9, 2006 first, you just need to see if the IP is existing in the DB already. if it's not, run the code you've already got going:[code]$ip = $_SERVER['REMOTE_ADDR'];$sql = mysql_query("SELECT COUNT(*) AS count FROM tableName WHERE ip = '$ip'");if (mysql_result($sql, 0, 'count') > 0) // they've already been hereelse { // run your increment code here}[/code]hope this helps! Link to comment https://forums.phpfreaks.com/topic/4556-count-from-database/#findComment-15900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.