Jump to content

Archived

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

brown2005

hits count

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?

Share this post


Link to post
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)

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.