1

I need help with the code. I building a housekeeping for moderation in a game. And in the game you could be banned. No problems there but when I want to write the bans expire time in housekeeping the mysql structure for just expire time is writen in DOUBLE (unix time). How do I convert it in the housekeeping so you could read the timeformat normal?

Maybe this question is asked before but I need help with the code, cause Im not a pro coder haha. How should I write the code?

I have like this:

$getBans = mysql_query("SELECT * FROM `bans`");
$page_number    = $_GET['page_number'];
if(!isset($_GET['page_number']) || !is_numeric($_GET['page_number']))
{
    $page_number = 1;
}
$pages      = mysql_num_rows($getBans);
$per_page   = "15";
$last_page  = ceil($pages/$per_page);
if ($page_number < 1)
{
    $page_number = 1;
}
    else if($page_number > $last_page)
{
    $page_number = $last_page;
}
$max    = 'LIMIT ' .($page_number - 1) * $per_page .',' .$per_page;
$data_p = mysql_query("SELECT * FROM `bans` ORDER BY `id` DESC $max ");
$next_page          = $page_number+1;
$previous_page      = $page_number-1;
echo "
<div class='center80'>
    <table class='zebra-striped'>
        <thead>
            <tr>
                <th>Ban ID</th>
                <th>Type</th>
                <th>Value</th>
                <th>Reason</th>
                <th>Banned By</th>
                <th>Expires</th>
                <th>More Information</th>
            </tr>
        </thead>
        <tbody>";
        if(mysql_num_rows($getBans) == 0)
        {
            echo("<tr><td>There are no bans to display</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
        }
            else
        {
            while($ban = mysql_fetch_array($data_p))
            {
                $banid      = $ban['id'];
                $bantype    = $ban['bantype'];
                $banvalue   = $ban['value'];
                $banreason  = $ban['reason'];
                $banexpire  = $ban['expire'];
                $banaddedby = $ban['added_by'];
                $banaddedon = $ban['added_date'];
                $banappeal  = $ban['appeal_state'];
                $banuserid  = $users->user_Data($banvalue,"id");

                echo("<tr><td>".$banid."</td><td>".$bantype."</td><td>".$banvalue."</td><td>".$banreason."</td><td>".$banexpire."</td><td>".$banaddedby."</td><td>");

And the time in housekeeping now shows this under "Expires": 1532908334.8502.

What should I write in the code to convert it to normal date and time?

Thanks

Anthon
  • 19
  • 5
  • Any particular reason you didn't use `timestamp` field in MySQL, opposed to `double`? Check PHP's [date()](http://php.net/manual/en/function.date.php) function and [DateTime class](http://php.net/DateTime). – Mjh Jan 29 '16 at 10:11
  • Its not my database from the first start. I have tried change to timestamp in structure but bans expire will be 0 in that way.. :/ – Anthon Jan 29 '16 at 10:14
  • Try `from_unixtime()` function to get date time – Abhishek Ginani Jan 29 '16 at 10:16
  • How should I write the code? – Anthon Jan 29 '16 at 10:17
  • Maybe this question has been asked before but I don't understand where I should use the from_unixtime() and that.. So I need help with that. – Anthon Jan 29 '16 at 10:31

0 Answers0