Princess Toledo
Princess Toledo

Reputation: 99

PHP: not getting the last row in my database

I have a new problem right now, and I was wondering why its not displaying..

Scenario:

I have a duration where the duration is good only until 10:00....

In my database:

bldgName    duration

blgA         9:55
bldgA        9:40
bldgB        1:40

As we can see, my last row if I used the "DESC" its look like that... So my last entry in my bldgA is 9:55... I will add another 5s under bldgA and it will become 10:00, which is correct... So here's my database as for now..

Current database after adding the 5 seconds.

bldgName    duration

blgA         10:00
blgA         9:55
bldgA        9:40
bldgB        1:40

Here's my query:

$radio = mysql_query("SELECT fldBldgName, MAX(fldTotalDuration) as fldTotalDuration FROM tbldata WHERE fldNetname = '".$get_radio."' AND fldMonth = '".$get_month."' AND fldWeek = '".$get_week. "' GROUP BY fldBldgName ORDER BY id, fldBldgName, fldTotalDuration DESC");

So when the program read that query above...

the output is like this...

bldgName    duration

blgA         9:55
bldgB        1:40

This is wrong...

the correct output is

bldgName    duration

blgA         10:00
bldgB        1:40

And also, I don't have any filtering yet when the duration meets the 10:00

Thanks for advance...

Upvotes: 0

Views: 94

Answers (2)

Princess Toledo
Princess Toledo

Reputation: 99

Instead of changing it to INT or DECIMAL, I just decided to change to TIME... So its already works now...

And also thank you for commenting and give some ideas thats make it help alot..

Upvotes: 0

Gnagno
Gnagno

Reputation: 607

I think I understood what he means. Seems like you want to get the max duration, is fldTotalDuration to type varchar? if yes it's normal that the max one is 9:55 because the field is alphabetically sorted, I suggest you to change the field type to decimal and it should work.

Bye Gnagno

Upvotes: 1

Related Questions