Skip to content
Advertisement

convert some value from mysql query using php

using php I make a query to mysql. Inside my query, some values are in seconds (just some of them), I’d like to convert them into mm:ss. So I need to move into my “array” query and I do not understand how to move inside my query result, attribute after attribute.

Here is my db :

enter image description here

In my php code, I make the query and then for each row I put it inside an array.

JavaScript

I’d like then to move into my array, and when I have the attribute CS for example, convert the value.

Here is what I tried :

JavaScript

I got an error. I don’t know how to move into my array, a select a element of a object. I thought I did it good but apparently no.

Thank you for you help.

Advertisement

Answer

mysqli_fetch_object returns objects, not arrays. Also you used $value instead of $value->CS inside of gmdate. So you should iterate like this:

JavaScript

Alternativly you can write this directly in your while loop, so you don’t need the foreach loop. I would say this is the better solutions because you don’t write unnecessary code and performance gets improved a little bit:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement