Jump to content

Recommended Posts

I stumble around PHP as I know very little of it. I'm trying to figure out how to create a page that shows the most played games from my site for the last hour, day, week, and month AND (if possible) the games from the last hour, day, week, and month that have a certain amount of plays. (IE: games for the last month that have 1000 plays or more, 2000 plays or more, etc.

 

The code block that I have to display the latest 100 games looks like this:

 

if (strlen($gid) == 0) {
$query4 = "SELECT gId, gName, gDescription, gThumb, gplays FROM games ORDER BY gId DESC LIMIT 100";
$result4 = mysql_query($query4) or die("Borked Query");
while (list ($id, $name, $description, $thumb, $played) = mysql_fetch_row($result4)) {

 

and (if needed) I have this code that displays the 100 most played games:

 

if (strlen($gid) == 0) {
$query4 = "SELECT gId, gName, gDescription, gThumb, gplays FROM games ORDER BY gplays DESC LIMIT 100";
$result4 = mysql_query($query4) or die("Borked Query");
while (list ($id, $name, $description, $thumb, $played) = mysql_fetch_row($result4)) {

 

Can somebody please give me an example using these two codes of how I can get my requested pages? If it is impossible to calculate the time as there is no date stamp that I know of or see in the code, please help me with how I could do it not based on time (hour,day,week.month), but instead by the last 100 games, 200 games, 300 games, etc.

 

Thanks for any help you can supply me with!

Link to comment
https://forums.phpfreaks.com/topic/125684-trying-to-figure-out-php-statement/
Share on other sites

Im not sure if I am understanding right or not.. but from what I gather.. you dont have a means of tracking the actual plays per game.. You may need a a couple new tables.. each with a row representing each game.. and then each table representing a day week month.. you break each row into columns day broken into colums representing hours in the day, week broken down into days month broken down with each month..

 

Now the concept..

At the begining of everday at a time you define, your "Days Table" gets wiped clean..

You have the table broken down into columns one column for each hour, every time a game is played it checks the hour and adds +1 to the count for that hour. Now at the end of the day before the table is wiped clean you run a script that takes the total for each row/game combines the total of those hours and adds it to the day column in the week table.. now follow suit in similar concept for month and year..

 

Now there may or may not be a simpler way to do this, but this is the first random thought that comes to mind that fits what I think your trying to do..

Counting actual time passing isn't as important. As I know how many games are released daily, I can simply do it like clockwork from how many recent games. So if I want a weeks worth of stats, all I need to do is do the code for the latest 50 games.

 

In the code that I gave the var "gplays" is gameplays, "gId" is the number that organizes the games (lower = older, higher or latest # = newer game, "gName" is for game name, "gDescription" is for game description, and "gThumb" is for the game thumbnail.

 

I don't need any help with the layout so the game name, description and thumb can be ignored, but I'm pretty sure a statement can be created with the gplays and the gId variables using some type of "ORDER" command to organize the games in the way I want it to.

 

Looking at the code I posted in the original post, I simply need it to allow a range of the "gId" variable, and a range for the "gplays" variable. Can somebody help me with that?

 

From what I understand of it myself, it should only be changes to this line:

 

$query4 = "SELECT gId, gName, gDescription, gThumb, gplays FROM games ORDER BY gId DESC LIMIT 100";

 

But where it states "ORDER BY gId" in that code, I need it to have code that allows the variable that I use, whether it be the "gId" (game id) or the "gplays" (gameplays) to be within a range from one number to another.

 

The gameplay variable "gplays" I need a range from one number to another.

The game id variable "gId" I need it to be a range from the ending, or very last number (could be 99999 if that works to 100 games back, 200 games back, etc.

 

Once the code is setup, I can plug in what numbers those two variables should be, but I don't know how the statement should look.

 

Please help.

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.