Jump to content

Archived

This topic is now archived and is closed to further replies.

brown2005

count from database

Recommended Posts

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...

Share this post


Link to post
Share on other sites
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 here
else {
  // run your increment code here
}
[/code]

hope this helps!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.