1

I have this application where I want to display various albums from musicartists. My issue though is that the track_duration-field gives me for example 00:04:16 but what I want is 04:16 - so I tried to integrate the MySQL SUBSTRING-function but without luck.

My original MySQL-string looks like this:

SELECT products.title AS album_title, products.genre AS album_genre,
    products.ccws_pro_id AS product_upc, track_title, track_duration 
    FROM products
INNER JOIN track_albumn_information ON products.ccws_pro_upc = track_albumn_information.product_upc 
AND track_albumn_information.artist_id =  '".$artist_id."'  LIMIT 0 , 30

So, I tried to do track_duration, SUBSTRING(track_duration, 3) FROM products...

But that didnt work. It returned the same value 00:04:16.

How can i do this ?

2
  • 1
    Define didn't work. Was there an error? Was the result other that the expected one? If yes, what? Commented Mar 19, 2014 at 9:11
  • @AndriusNaruševičius I updated my question, it returned the same value.. Commented Mar 19, 2014 at 9:14

2 Answers 2

3

You are selecting both the original and the modified version.

Because you didn't give the substring version an alias, your PHP will be seeing a field that is literally called SUBSTRING(track_duration, 3), plus the original as track_duration.

Looks like you just want the modified version, which can be done by giving it an alias:

SELECT products.title AS album_title, products.genre AS album_genre, products.ccws_pro_id AS product_upc, track_title, SUBSTRING(track_duration, 3) AS track_duration FROM products

Now in your PHP if you output the track_duration field for the rows, it will contain the modified data.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm I use BackboneJS for my frontend, so I dont output the track_duration with echo $track_duration. The query returns the data as JSON, so somehow this does not work...
2

You should check if there are realy leading zeros, otherwise you can do a "replace" by

SELECT TRIM(LEADING '00:' FROM '00:04:16');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.