Jump to content


Photo

hits count


  • Please log in to reply
1 reply to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 09 March 2006 - 09:49 PM

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?


#2 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 10 March 2006 - 12:23 AM

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)
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users