Jump to content


Photo

count from database


  • Please log in to reply
1 reply to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 09 March 2006 - 08:26 PM

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


#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 09 March 2006 - 08:33 PM

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:
$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
}

hope this helps!
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users