I want to list the last record in the table and display, but I can not.
The reports table has the field registration date duration and destination_id
registration date time duration destination_id
2501 2014-03-22 08:25:00 00:40:00(timestamp) SBGL
2501 2015-07-25 10:03:00 00:40:00(timestamp) SBRJ
5531 2015-09-15 19:24:00 00:40:00(timestamp) SBSM
5531 2015-10-19 10:15:00 00:40:00(timestamp) SBBR
I want to show the last destination_id for registration 2501 and 5531. That is to say that:
2501 => SBRJ
5531 => SBBR
In the code below it returns:
2501 => SBGL
5531 => SBSM
Does anyone help pf?
$hours = mysql_query("SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( duration ) ) ) AS duration_sum FROM reports GROUP BY registration");
$regist = mysql_query("SELECT registration AS regist FROM reports GROUP BY registration");
$model = mysql_query("SELECT equipment AS model FROM reports GROUP BY registration");
$base = mysql_query("SELECT destination_id FROM reports");
while($row = mysql_fetch_array($hours) AND $row2 = mysql_fetch_array($regist) AND $row3 = mysql_fetch_array($model) AND $row4 = mysql_fetch_array($base)){
<tr>
<td align="center"><div align="left"><? echo($row3['model']); ?></div></td>
<td align="center"><div align="left"><? echo($row2['regist']); ?></div></td>
<td align="center"><div align="center"><? echo($row['duration_sum']); ?></div></td>
<td align="center"><div align="center"><? echo($row4['destination_id']); ?></div></td>
</tr>
<?php
}//while