Forum Moderators: coopster
This will successfully print out the date in the correct format with echo, but I am unsure of how to roll that into my loop below. I am new to php and not sure if there is way to simply push the code above into my select statement and make it a part of $query? If not, how would I add the converted timestamp into this line? $output .= '<td align="center">' . $row['submitted'] .'</td>';
This is my entire function:
function ShowList(){
$output = '<table border="1" width="700" cellpadding="5" style="border-collapse: collapse; border-color: black">
<tr bgcolor="#ADAAAA" bordercolor="black">
<th>ID#</th>
<th>Employer</th>
<th>Name</th>
<th>Month</th>
<th>Year</th>
<th>Submitted</th>
<th width="76">Action</th>
</tr>';
// run the query, order by Name
$query = mysql_query("select from Data order by Employer asc, Name asc");
// loop all the records
while($row = mysql_fetch_assoc($query)){
$output .= '<tr bordercolor="black" bgcolor="#C4F5BF">';
$output .= '<td align="center">' . $row['ID'] .'</td>';
$output .= '<td align="center">' . $row['Employer'] . '</td>';
$output .= '<td align="center">' . $row['Name'] .'</td>';
$output .= '<td align="center">' . $row['Month'] .'</td>';
$output .= '<td align="center">' . $row['Year'] .'</td>';
$output .= '<td align="center">' . $row['submitted'] .'</td>';
$output .= '<td valign="top" width="96"><a href="?action=edit&ID=' . $row['ID'] . '">Edit</a> - ';
// need to add slashes as we're dealing with javascript here
$output .= '<a href="javascript:checkDelete(\'' . addslashes($row['Name']) . '\',\'' . addslashes($row['Month']) . '\',\'' . addslashes($row['Year']) . '\',' . $row['ID'] . ');">Delete</a></td>';
$output .= '</tr>';
}
$output .= '</table>';
return $output;
}
First your query needs to be like this:
// run the query, order by Name
$query = mysql_query("select * from Data order by Employer asc, Name asc");
Then when echoing the date:
$output .= '<td align="center">' . date("m/d/y - g:ia",strtotime($row['submitted'])) .'</td>';