Nick Cotter
Nick Cotter

Reputation: 13

Time Checking in PHP

To start off I'm sorry for the noob question. Learning as I go but I'm having issues with this and couldn't fine the right search.

What I'm trying to accomplish:

For example a person is banned for 40 minutes, In the SQL database it is stored as the value 40.That is fine when displayed in a table however issues arise when a person is banned for 10080 minutes (1 week)

What I have:

$sql = "SELECT name, authid, name, length FROM sb_ctbans";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
     if ($row["length"]  < '60'){
          $row["length"] . "Minutes"  == $ban['length'];
          echo $ban['length'];
        } else {
            $row["length"] . "Undefined length" ==   $ban['length'];
    }
        echo "<tr>"."<td>" . $row["name"] ."</td>" . "<td>" . $row["authid"] ."</td>" . "<td>" . $ban['length'] . "</td>"   ."</tr>";
    } 

Expected output: 2 Minutes Actual output:

Cheers for any help.


Edit: After changing from:
$row["length"] . "Minutes" == $ban['length'];

To:

      `        $ban['length'] = $row.['length'] . 'Minutes';`

I am now reviving the output ArrayArray Minutes

Upvotes: 1

Views: 72

Answers (1)

Sgt AJ
Sgt AJ

Reputation: 863

You have a couple of problems here. You fixed the first wrong line, but it's again wrong at $row["length"] . "Undefined length" == $ban['length'];. Also, you're checking if the $row['length'] is less than the STRING '60', not the number 60, which could be causing errors. Finally, as others have said, storing the number of minutes to ban is sure to cause problems eventually. Instead, when the ban is first established, calculate the time it will be when the ban expires and store that instead. When you check it, calculate how long til the time you stored. Otherwise as time passes, you must update every ban record every minute or they become inaccurate.

Upvotes: 1

Related Questions