Home  >  Q&A  >  body text

How to filter out rows whose last login time is in the past 3 days or longer

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粉071559609P粉071559609401 days ago554

reply all(1)I'll reply

  • P粉269530053

    P粉2695300532023-09-15 12:27:17

    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>";

    }

    reply
    0
  • Cancelreply