Jump to content

login days in a row


jwk811

Recommended Posts

this is driving me crazy. what im trying to see if count how many days a user logs in in a row.

 

the first part works where it checks to see if they logged in yesterday if yes it adds to the login days. if no it checks to see if its been longer than yesterday in that case it would go back to 0. if they are logging in again that day it wont do anything.

 

$yesterday  = date('Y-m-d 00:00:00', strtotime('-1 day'));
$yesterday2 = date('Y-m-d 23:59:59', strtotime('-1 day'));

$sql = "SELECT user_last_login FROM tbl_user
        WHERE user_id = '{$row['user_id']}' AND user_last_login >= '$yesterday' AND user_last_login <= '$yesterday2'";
$result = dbQuery($sql);

if(dbNumRows($result) == 1){

            $sql = "UPDATE tbl_user 
                    SET user_daily = user_daily + 1
                    WHERE user_id = '{$row['user_id']}'";
            dbQuery($sql);
}
else{

$sql = "SELECT * FROM tbl_user
        WHERE user_id = '{$row['user_id']}' AND user_last_login > '$yesterday'";
$result = dbQuery($sql);


	if(dbNumRows($result) == 1){

           		 $sql = "UPDATE tbl_user 
            	        SET user_daily = 1
             	   	    WHERE user_id = '{$row['user_id']}'";
           		 dbQuery($sql);

	}
}

 

$sql = "SELECT * FROM tbl_user

        WHERE user_id = '{$row['user_id']}' AND user_last_login > '$yesterday'";

$result = dbQuery($sql);

 

 

if(dbNumRows($result) == 1){

 

^^ that part isnt working. for some reason its not getting that its been longer than yesterday and ive changed it to over a week since last login and it wont do it. its not getting any rows its not a problem with the update. please help

Link to comment
https://forums.phpfreaks.com/topic/158428-login-days-in-a-row/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.