$query = "SELECT * FROM blah WHERE id = 9";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) == 0) {
echo "no records found";
} else {
// Display records
}
That would be good, but what I am trying to do is this.
Everytime a person enters the website their IP is recorded and the counter is added by 1. However if their IP is already there it stays the same. How would I make it add by 1 when the IP is not found in the database?
$sql = "SELECT * FROM table WHERE ip=$ip";
$res = mysql_query($sql);
if (mysql_num_rows($res) == 0){
$sql = "INSERT INTO table ip,count VALUES ('$ip', '1')";
mysql_query($sql);
}elseif (mysql_num_rows($res) == 1){
$sql = "UPDATE table SET count=count + 1 WHERE ip='$ip'";
mysql_query($sql);
}else{
echo "IP was found more than once....";
}
This sin;t tested but it should work... unless i might've misspelled a few things!!
McGruff wrote:Unfortunately that's not reliable. There's dynamic IPs and AOL users can even have different IPs within the same session.
I didn't even know! Glad to read about this useful information
The counter script I worked on checks to see if a cookie has been set (the cookie goes for 60 days) and if it hasn't it also checks if the IP is in the database... kinda redundant and not very useful but it keeps from double entries Also, I don't keep a number in the database of how many visitors have come... I just count the rows in the table that are inserted everytime a new visitor comes
it is from my understanding that counters can never be 100% reliable and you should never take there information as gospel truth
counters are useful for getting a very good estimate for how many people you have on-line (my localhost PHPBB often gives me 2 people on-line when theres only me)