I'm trying to make a script that is similar to a Users Online script, but instead I want it to keep a current record of the unique visitors to my site a day. I came up with this, but I'm not sure if it's efficient/the best way to do it. 3 queries seem like a bit much to me, but ya'll can be the judge of that. 🙂
<?php
connect_to_db();
$day_date = date("md");
$delete_query = "DELETE FROM users_online WHERE date<>'$day_date'";
mysql_query($delete_query);
$insert_query = "INSERT INTO users_online (IP, date) VALUES('$REMOTE_ADDR', '$day_date')";
mysql_query($insert_query);
$select_query = "SELECT DISTINCT IP FROM users_online WHERE date='$day_date'";
print(mysql_num_rows(mysql_query($select_query)));
?>
See any problems/suggestions? Thanks!