*

Recent

Author Topic: Total Game Plays  (Read 4625 times)

am-fs

  • Owner
  • Developer
  • Full Member
  • ******
  • Posts: 228
  • Force: +1/-0
    • Great Flash Games
Total Game Plays
« on: October 21, 2011, 09:47:47 PM »
Got a mod for total game plays instead of page hits?

I know it should be something like
Code: [Select]
$totalplays = $db->num_rows($db->query(sprintf('SELECT sum(views) AS totalpays FROM dd_games WHERE active="1"')));
Display
Code: [Select]
Total Games Played: <? echo $totalplays; ?>
But No Luck


Adam LaCombe

  • Sr. Member
  • ****
  • Posts: 433
  • Force: +17/-0
    • My Blog
Re: Total Game Plays
« Reply #1 on: October 21, 2011, 09:54:31 PM »
You got a typo..
SELECT sum(views) AS totalpays

maybe that will fix it?

am-fs

  • Owner
  • Developer
  • Full Member
  • ******
  • Posts: 228
  • Force: +1/-0
    • Great Flash Games
Re: Total Game Plays
« Reply #2 on: October 21, 2011, 10:19:28 PM »
still incorrect number and it dont count

Adam LaCombe

  • Sr. Member
  • ****
  • Posts: 433
  • Force: +17/-0
    • My Blog
Re: Total Game Plays
« Reply #3 on: October 21, 2011, 10:38:14 PM »
hmmm...

Code: [Select]
<?php
$query 
"SELECT sum(views) FROM dd_games WHERE active='1'"
$result mysql_query($query) or die(mysql_error());
$row mysql_fetch_array($result);
echo 
$row['SUM(views)'];
?>


am-fs

  • Owner
  • Developer
  • Full Member
  • ******
  • Posts: 228
  • Force: +1/-0
    • Great Flash Games
Re: Total Game Plays
« Reply #4 on: October 21, 2011, 11:20:07 PM »
Still Nothing, ill keep digging  ;)

Adam LaCombe

  • Sr. Member
  • ****
  • Posts: 433
  • Force: +17/-0
    • My Blog
Re: Total Game Plays
« Reply #5 on: October 21, 2011, 11:59:44 PM »
okay lol sorry I would try to debug it but I don't have a working FAS site on my server yet. Had to wipe the server clean and start over again.. just haven't had lots of time to put FAS back up.

check out http://www.tizag.com/mysqlTutorial/mysqlsum.php
and the people over at PHPFreaks are wonderful at helping. http://phpfreaks.com/

Frank

  • Sr. Member
  • ****
  • Posts: 257
  • Force: +4/-0
Re: Total Game Plays
« Reply #6 on: October 22, 2011, 02:48:54 AM »
Try this. ;)

Code: [Select]
<?php
// Total Games Played

$query "SELECT views, SUM(views) FROM dd_games WHERE active=1"
$result mysql_query($query) or die(mysql_error());

// Get result
while($row mysql_fetch_array($result)){$row['SUM(views)'];
$totalgameplays $row["SUM(views)"];
}
?>



// Print it out

HTML:
<?php echo $totalgameplays?>

PHP:
'.$totalgameplays.'


Put the script in php, Use the anchor as appropriate and decorate them with some mark-up. :)
« Last Edit: October 22, 2011, 03:49:35 AM by mort »

am-fs

  • Owner
  • Developer
  • Full Member
  • ******
  • Posts: 228
  • Force: +1/-0
    • Great Flash Games
Re: Total Game Plays
« Reply #7 on: October 22, 2011, 08:47:56 AM »
Right On .............. mort  8) ;D

Thanks



Adam LaCombe

  • Sr. Member
  • ****
  • Posts: 433
  • Force: +17/-0
    • My Blog
Re: Total Game Plays
« Reply #8 on: October 22, 2011, 12:19:02 PM »
That works, but you really don't wanna do that..
That will make your server work over time. If you really wanna do it that way then I would recommend caching the results for a one day time period.
but even if you do caching results...
If you have thousands of games just imagine how long it will take to run through that while. It could even take so long that it won't display. Default slow queries stop at 30 seconds, after 30 seconds it stops loading the data and displays a error message.

Frank

  • Sr. Member
  • ****
  • Posts: 257
  • Force: +4/-0
Re: Total Game Plays
« Reply #9 on: October 22, 2011, 03:41:13 PM »
If it ever gets to be a problem with the charge on the Db, one could possibly do a Cron Job on it once a week. ;)

Because if one has so many games that have been played - Then hourly or daily updates would be insignificant.

As for "time-out" One could expect that from places like GoDaddy and a few others - And sometimes that's most of the problem.
:(

Adam LaCombe

  • Sr. Member
  • ****
  • Posts: 433
  • Force: +17/-0
    • My Blog
Re: Total Game Plays
« Reply #10 on: October 22, 2011, 04:44:16 PM »
I suppose.. still would try to think of a better way of doing it.

No, everyone that runs a mysql database will get those errors. Unless you higher the limit from 30 seconds to something like 2 mins.. but I highly do not recommend doing so.
That limit is there to make sure you don't kill your server lol

I myself am struggling with slow queries. I got 16+ million rows of data that needs to be searched through to find results and it takes about 18 seconds for a query to execute. Wayyyy too long.
I'm trying to build a flat file database system to fix that slowness.

But.. I think doing something like a mix of caching the total game plays and a counting plays execution file would work.
soo basically create a php file and loop through 100 games at a time then have the script wait about 25-30 seconds and loop through another 100 games starting from id 101 and so on.
Just put that into a for loop and stop the loop at the amount of active games.
then cache the results. You could run that every day if you wanted, but if you got thousands of games I would say every 2-5 days.
and yup I would say do a cron job on it, if you're lazy and forgetful like myself  :D