cloudsurferuk Posted February 2, 2010 Share Posted February 2, 2010 Ok, Tried all I know but cant seem to get my head round this. Basically the following code looks at all the fields in one table (acars_pirep) for the specified crew member and displays the total of blocktime. However block time is a numerical figure representing minutes i.e. if they have flown 1hr 30mins the report shows 90. Now the code works fine and adds all the hours up and gives me a total value but this is obviously in the minutes form i.e. 90, now how can change the code so it converts 90 into 1:30 for display purposes? Code being used $query = "SELECT * FROM pilots ORDER BY pilot_num ASC"; $result = mysql_query($query); $number = mysql_numrows($result); if ($number > 0) { print "<table>"; print "<tr>"; print "<td bgcolor=#CC6600 width=50 height=12 align=left><font face=Arial color=#000000 size=1><b>Pilot ID</b></font></td>"; print "<td bgcolor=#CC6600 width=150 height=12 align=left><font face=Arial color=#000000 size=1><b>Name</b></font></td>"; print "<td bgcolor=#CC6600 width=150 height=12 align=left><font face=Arial color=#000000 size=1><b>City</b></font></td>"; print "<td bgcolor=#CC6600 width=30 height=12 align=left><font face=Arial color=#000000 size=1><b>Loc</b></font></td>"; print "<td bgcolor=#CC6600 width=73 height=12 align=left><font face=Arial color=#000000 size=1><b>Total (Mins)</b></font></td>"; print "<td bgcolor=#CC6600 width=73 height=12 align=left><font face=Arial color=#000000 size=1><b>Rank</b></font></td>"; print "<td bgcolor=#CC6600 width=73 height=12 align=left><font face=Arial color=#000000 size=1><b>Prev Hours</b></font></td>"; print "</tr>"; for ($i=0; $i<$number; $i++) { $num = mysql_result($result,$i,"pilot_num"); $name = mysql_result($result,$i, "name"); $city = mysql_result($result,$i, "city"); $country = mysql_result($result,$i, "country"); $status = mysql_result($result,$i, "status"); $previous_hours = mysql_result($result,$i, "previous_hours"); $id = mysql_result($result,$i, "pilot_id"); $query_hours = "SELECT sum(t2.blocktime) AS duration_sum FROM pilots t1, acars_pirep t2 WHERE t1.pilot_id=$id AND t1.pilot_id=t2.iduser"; $result_hours = mysql_query($query_hours); if (mysql_numrows($result_hours) > 0) { $time = mysql_result($result_hours,0,"duration_sum"); } print "<tr>"; print "<td width=50 height=12 align=left><font face=Arial size=1 color=#000080><a href='crewcentre.php?focus=15&fsbid=$id'>$num</a></font></td>"; print "<td width=150 height=12 align=left><font face=Arial size=1 color=#000080><a href='crewcentre.php?focus=15&fsbid=$id'>$name</a></font></td>"; print "<td width=150 height=12 align=left><font face=Arial size=1 color=#000080>$city</font></td>"; print "<td width=30 height=12 align=left><font face=Arial size=1 color=#000080>$country</font></td>"; print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$time</font></td>"; print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$status</font></td>"; print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$previous_hours</font></td>"; print "</tr>"; } print "</table>"; } Link to comment https://forums.phpfreaks.com/topic/190636-possibly-basic-mins-to-hours-question/ Share on other sites More sharing options...
jl5501 Posted February 2, 2010 Share Posted February 2, 2010 <?php $mins = 90; echo (int)($mins / 60) .':'. $mins % 60; ?> Link to comment https://forums.phpfreaks.com/topic/190636-possibly-basic-mins-to-hours-question/#findComment-1005386 Share on other sites More sharing options...
cloudsurferuk Posted February 2, 2010 Author Share Posted February 2, 2010 Ok thanks for the quick reply, but, using the code above, where would I slot that in to get the total in hours/mins displayed under the $time field of the table? (sorry if this appears basic but we all have to learn ) Link to comment https://forums.phpfreaks.com/topic/190636-possibly-basic-mins-to-hours-question/#findComment-1005393 Share on other sites More sharing options...
jl5501 Posted February 2, 2010 Share Posted February 2, 2010 You can set a variable $display_time = (int)($mins / 60) .':'. $mins % 60; and then display that where you have your $time variable displayed Link to comment https://forums.phpfreaks.com/topic/190636-possibly-basic-mins-to-hours-question/#findComment-1005395 Share on other sites More sharing options...
cloudsurferuk Posted February 2, 2010 Author Share Posted February 2, 2010 thanks for your help Link to comment https://forums.phpfreaks.com/topic/190636-possibly-basic-mins-to-hours-question/#findComment-1005479 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.