How to filter out rows whose last login time is in the past 3 days or longer
P粉071559609
P粉071559609 2023-09-14 14:29:17
0
1
577

I'm trying to write a feature for my service, but I'm having some difficulty getting it to work.

Basically, I want to write a function that logs users who haven't logged in for more than 3 days, but it just doesn't work.

My current code is as follows:

$findActivity = mysqli_query($conn, "SELECT * FROM users WHERE 'last_active' < CURRENT_TIMESTAMP - 3 DAY");
while($activeRow = mysqli_fetch_assoc($findActivity)){
    
    $usr = $activeRow['username'];;
    $la = $activeRow['last_active'];

    echo "<tr class='row100 body'>";
    echo "<td class='cell100 column3'>$usr</td>";
    echo "<td class='cell100 column3'>$inactivefor</td>";
    echo "<td class='cell100 column3'>$msg</td>";
    echo "</tr>";
}

I basically want it to output those accounts that have not been logged in for more than 3 days.

P粉071559609
P粉071559609

reply all(1)
P粉269530053

Try this:

$findActivity = mysqli_query($conn, "SELECT * FROM users WHERE last_active < 
CURRENT_TIMESTAMP - INTERVAL 3 DAY");
while ($activeRow = mysqli_fetch_assoc($findActivity)) {
$usr = $activeRow['username'];
$la = $activeRow['last_active'];

echo "<tr class='row100 body'>";
echo "<td class='cell100 column3'>$usr</td>";
echo "<td class='cell100 column3'>$la</td>";
echo "</tr>";

}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!