Jump to content

hits count


brown2005

Recommended Posts

if ($_GET['id'])
{

$sq1 = mysql_query("SELECT COUNT(*) AS count FROM ads_hits WHERE hits = '".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."'");

if (mysql_result($sql, 0, 'count') > 0)
{
$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();
}
else
{
$sql_2="insert into ads_hits(hits,hits_id,hits_ip,hits_count) values('".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."','".$_GET['id']."','".$_SERVER['REMOTE_ADDR']."','0')";
$res=mysql_query($sql_2);
echo ADDED;
exit();
}

}

i have this code which inserts data into the database, but if the record is allready in the database it does not add 1 to the hits_count.

can anyone help?
Link to comment
Share on other sites

if ($_GET['id']) {
$sq1 = mysql_query("SELECT COUNT(*) AS count FROM ads_hits WHERE hits = '".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."'");
if (mysql_result($sql, 0, 'count') > 0){
$sql2 ="UPDATE ads_hits SET hits_count= hits_count +1 WHERE hits='".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."' ";
$updated=true;
mysql_query($sql2);
die("Finished!");
}else{
$sql_2="insert into ads_hits(hits,hits_id,hits_ip,hits_count) values('".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."','".$_GET['id']."','".$_SERVER['REMOTE_ADDR']."','0')";
$res=mysql_query($sql_2);
die("Added!");
}

}


heres your code tidyed up a bit, some bits are confusing, and can be done so much better and accuate. if your stuck on this code still, i can remake it for £5. joe@joeyjoe.co.uk (msn)
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.