Well,

I must admit Im gotten abit to familiar with the use of MySQL lately,
though it might be abit overkill - but what the heck. The database is
there to be used and we shouldnt worry to much. For those really
worrying there are several file based "sql" alternatives out there.

Ok, I would use and update statement against the SQL database,
soething like :

update my_stats_table set counter=counter+1 where id=1

All you need is to fire this query on every page, well, you might have
different counters for different pages I just used the ID=1 as an
example, it might aswell be "page='frontpage'"

If you need a more dynamic sollution, meaning you have contents that
you want logged that change from time to time - and you do not
want to prepare the database all the time you could do it like this,
remember
I use a DB extraction layer function named query, so whenever I write
query I really mean mysql_query... Assuming your counting banners

query("update my_stats_table set counter=counter+1 where id=" .
md5($bannername));
if(!mysql_affected_rows)
    query("inserted my_stats_table (id, counter) VALUES ('" .
md5($bannername) . "',1)");

You see the logic with the mysql_affected_rows. Now your still stuck with
doing
some nifty stats generating from the data you have in your table - but now
you have
numbers in the database and you have several options.

One that suddenly comes to mind, is always showing the one with the smallest
impressions.

$result = query("select * from my_stats_table where order by counter limit
1");

You would here need to add more information, probably might aswell include
the entire
banner in the database.

Well, BTW, hope this helps you.
--
--
Kim Steinhaug
----------------------------------------------------------------------
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
----------------------------------------------------------------------
www.steinhaug.com - www.easywebshop.no - www.webkitpro.com
----------------------------------------------------------------------



on Sun, 13 Jun 2004 01:15:20AM +0200, Kim Steinhaug insinuated:
> Hmm... Ive been having same problems with mysql and picking random
> numbers, I ended up having to program a rather more sofisticated
> system to eliminate the stats you were referring to.
>
> You could, not that it will be any better, try another approach :
>
> Something like :
>
> $count = count($your_data_array);
> $random = rand(0, $count);
> echo $your_data_array[$random];
>
> PHP is maby using the same random function for both the array_rand and
> rand for all I know but its worth a go.

yeah, since they use the same thing i'm not sure it'd be worth the
effort.

> The harder way would be to include an internal counter for your
> elements you want to be randomized, so that when an item is selected
> you count it. Then the next time you calculate the random element
> you take the accual hits into meassure.  There are like a 1000 ways
> to do this so use your imagination.

that would be cool.  but how do you maintain the value of a counter
from reload to reload?  would i have to open an external file, read
its variable, increment it, write to it, and close it every time?  or
is there a way to do that in the code of a single php page?

thanks again,

</nori>

--
    .~.      nori @ sccs.swarthmore.edu
    /V\  http://www.sccs.swarthmore.edu/~nori
   // \\          @ maenad.net
  /(   )\       www.maenad.net/jnl
   ^`~'^

++     Sponsor me as I run my SECOND marathon for AIDS:       ++
++ http://www.aidsmarathon.com/participant.asp?runner=DC-2844 ++

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to