tmfl Posted January 31, 2011 Share Posted January 31, 2011 Hi, I'm inserting hours and minutes per user into a database where they have their own fields. (userid, hours, mins) I've a small issue when displaying the data. When I run my query I sum the total hours and minutes per user which results in data such as the following userid1 - 2 hours 15 mins userid2 - 1 hour 100 mins The query orders by hours and then mins desc When I'm displaying the data (as I'm looping through the results array) I perform a calculation to convert the mins to hours so it now reads userid1 - 2 hours 15 mins userid2 - 2 hours 40 mins so the webpage displays userid1 first when i want userid2 to be the first record displayed (Hours desc) Can anyone recommend a solution to this ? Will I need to create another table and update it as hours and minutes are being entered and display results from that table instead ? Can I order the data after I carry out the mins to hours calculation ? many thanks in advance for any suggestions.... tmfl Quote Link to comment https://forums.phpfreaks.com/topic/226277-adding-time-values-and-displaying-in-correct-order/ Share on other sites More sharing options...
taquitosensei Posted January 31, 2011 Share Posted January 31, 2011 Store it as Minutes only sort by minutes and convert to Hours Minutes when you display it. 150 Minutes $minutes=150; echo floor($minutes/60)." Hour(s) ".($minutes%60)." Minute(s)"; // 2 Hour(s) 30 Minute(s) Quote Link to comment https://forums.phpfreaks.com/topic/226277-adding-time-values-and-displaying-in-correct-order/#findComment-1168039 Share on other sites More sharing options...
tmfl Posted January 31, 2011 Author Share Posted January 31, 2011 Thanks for the reply... At the moment the form I'm using has a dropdown for hours and a dropdown for minutes.... I guess converting it on the way in to minutes is the way you'd recommend then yeah ? thanks again tmfl Quote Link to comment https://forums.phpfreaks.com/topic/226277-adding-time-values-and-displaying-in-correct-order/#findComment-1168083 Share on other sites More sharing options...
taquitosensei Posted February 1, 2011 Share Posted February 1, 2011 yup ($hours*60)+$minutes Quote Link to comment https://forums.phpfreaks.com/topic/226277-adding-time-values-and-displaying-in-correct-order/#findComment-1168171 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.