Jump to content

Counting Number of Log Ins


Xtremer360

Recommended Posts

One more question to ask. I'm trying to do a count of total logins that have happened in the last 5 months including the current one so far.

 

My users_logins table has the following structure: users_id, session_id, login_date(datetime), last_activity(datetime).

 

What the end result is going to be is:

 

<tr>

    <td></td>

    <th scope="col"><?php echo date("M", strtotime("-4 month")); ?></th>

    <th scope="col"><?php echo date("M", strtotime("-3 month")); ?></th>

    <th scope="col"><?php echo date("M", strtotime("-2 month")); ?></th>

    <th scope="col"><?php echo date("M", strtotime("-1 month")); ?></th>

    <th scope="col"><?php echo date("M"); ?></th>

</tr>

<tr>

    <th scope="row">Logins</th>

    <td>94</td>

    <td>53</td>

    <td>124</td>

    <td>92</td>

    <td>105</td>

</tr>

 

Where the first td would be May and the last td would be September. Do I have to do this in 4 separate queries. If so here's what I have for the first query. I'm not sure what woudl go for the WHERE.

 

$four_months_ago_query = "SELCT COUNT(date_login) FROM users_logins WHERE ? ";

Link to comment
Share on other sites

I tried that code but lets say I change it to do:

 

SELECT COUNT( login_date )
FROM users_logins
WHERE login_date >= NOW( ) - INTERVAL 5
DAY
GROUP BY DAY( login_date )

 

Because after thinking about ti I want it to display the last 5 days instead. The query works as well. However since I've displaying the last 5 days how can I get it to show "0" for the last 2 days since there won't be any data for those days yet.

 

 

Link to comment
Share on other sites

What you really need to do is take a giant stick and shove it up your grande ass.. I mean :confused: uh.. I mean..

 

 

$homo= "SELECT * FROM users_logins WHERE login_date BETWEEN NOW() AND DATE_SUB(login_date , INTERVAL 5 day)"; 
$lesbians = mysql_query($homo) or die(mysql_error());

$totals = array();
while($yourMom = mysql_fetch_array($lesbians)){
      $z = 0;
      while($x=1;$x < 5;$++)
      {

          $compareTimes = strtotime(date('Y-m-d H:i:s') . ' +1 day');
          if(strtotime($yourMom['login_date']) <= strtotime('-".$x." day"))
          {
             $z++;
          }
      }
  array_push($totals, $z);
}


foreach($totals as $counted)
{
     echo $counted."<br>";
}

 

now will this work? I have no idea.. just kinda came up on this in a whim its a bit sloppy but it could work..

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

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.