Jump to content

count from database


brown2005

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...
Link to comment
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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.