I have a php look up from a drop down list. This will look up changes to a specific staff’s time card and return to a table. Works really well but I am having trouble returning the results from Line 2 and 5 and 7 to show real time not unix time, 2 is date effected, 5 is date requested and 7 in date approved/changed.
This is the code i am using.
<table border="1" width="75%" cellpadding="2" cellspacing="0">
<tr>
<td align="center">Date Effected</td>
<td align="center">Status requested</td>
<td align="center">Requested by</td>
<td align="center">Date requested</td>
<td align="center">Amended by</td>
<td align="center">Date amended</td>
</tr>
<?php
$host = "host";
$user = "USER";
$pass = "PWORD";
$dbname = "DB";
$loc = $fgmembersite->UserLocation();
$term = $_GET['button'];
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$query= "select * from $loc where User_id=$term";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($line = mysql_fetch_row($result) )
{
echo '<tr>';
echo '<td align="center">'.$line[2].'</td>';
echo '<td align="center">'.$line[3].'</td>';
echo '<td align="center">'.$line[4].'</td>';
echo '<td align="center">'.$line[5].'</td>';
echo '<td align="center">'.$line[6].'</td>';
echo '<td align="center">'.$line[7].'</td>';
echo '</tr>';
}
?>
</table>
any help gratefully revived. Thanks in advance
First, stop using
mysql_functions. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements as your code is vulnerable to SQL injection and use PDO or MySQLi – this article will help you decide which.If I understand correctly, you’re storing the date as a unix timestamp and need to convert it. It can be done with MySQL or PHP.
With MySQL, you can use
FROM_UNIXTIME().Manual
With PHP, you can use
date.Manual
I would also recommend that you specify a column list in your query, and use those columns rather than the index value.