SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hi, Php Counter Not Counting Unique Visitors HELP PLZ

    PHP Code:
    <?php
    include "config.php"

    $date date("Y-m-d"); 
    $ip $REMOTE_ADDR;

    $query "select * from count1 where ip='$ip'"
    $result mysql_query($query);
    $num mysql_num_rows($result); 

    if (
    $num != "0") { 
    $query2 "insert into count1 (ip) values ('$ip')"
    $result mysql_query($query2);
    }else{
    $query "UPDATE count SET hits = hits+1 WHERE date='$date'";
    $result mysql_query($query);

    ?>

    Its Updating the database
    but i want it to check the ip first

    so it checks it, And IFF it isnt In the db Already, add it into the db
    Iff it IS in the db, i dont want it to UPDATE!

  2. #2
    SitePoint Zealot sidhighwind's Avatar
    Join Date
    Aug 2003
    Location
    Indianapolis, IN
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this.
    PHP Code:
    <?php
    include "config.php"

    $date date("Y-m-d" );
    $ip $_SERVER['REMOTE_ADDR'];

    $query "select * from count1 where ip = '$ip'";
    $result mysql_query($query);
    $num mysql_num_rows($result);

    if(
    $num != 0) {
    // this would only happen if the ip is not in the database
    $query2 "insert into count1 (ip) values ('$ip')";
    $result mysql_query($query2);
    } else {
    // this is going to happen whenever the ip is found the the
    // database.
    // we use replace just to make sure that if the row doesnt exists
    // that it will create the row instead of trying to update a row that
    // does not exist.
    // replace will also update a row if it is found.
    $query2 "REPLACE count set hits = hits+1 WHERE date = '$date'";
    $result mysql_query($query2);
    }
    so it checks it, And IFF it isnt In the db Already, add it into the db
    Iff it IS in the db, i dont want it to UPDATE!
    do you want it to update the database or not? Look at the bolded line.
    Jon Whitcraft :: It's the Bombdiggity!
    Web Applications Developer :: Zend Certified Engineer
    http://www.indycar.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •