Re: Why won't this work?

From: Date: Fri, 19 Jul 2002 09:01:29 +0000
Subject: Re: Why won't this work?
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-108466@lists.php.net to get a copy of this message
hmm... seems a MySQL topic. I suppose that your table is filled with correct data at some other point. So what you need is a count query that returns *one* result and not all records in that table. You do not want a *while* loop in your PHP script, because that would show a list of unique ips. So my gues would be: $result = mysql_query("SELECT COUNT(DISTINCT IP) AS ips FROM ma_counter"); $ips = mysql_fetch_row($result); pintf("Visitors = %d",$ips); Disclaimer: code not tested. You might want to check the MySQL manual for syntax details of the query. Good luck René John Wulff wrote:
You're a savior, don't know how i missed that. Thanks a bunch. Now, one more quick question if you don't mind. I've got this query at the bottom of my page for the purpose of a counter. But naturally i don't want a list of all the ips logged, i just want a count of how many unique ips there are in the table. How do i go about this?<?php $result = mysql_query("SELECT distinct ip from ma_counter"); while(list($ip) = mysql_fetch_row($result)) { print ("$ip"); } ?>
<snip>
$mode = "entrance"; if ($mode == "entrance") {
     
</snip> I suppose you added the first line ($mode = "entrance"; ) for testing purposes during debugging, but in order for the script to work you should now remove it, because now $mode will always have the value "entrance" good luck René


« previous php.general (#108466) next »