I have this BackboneJS Application where I use Codeigniter as Backend. I use the RESTful API to return data from my MySQL Database to the Frontend. As part of my application, I want to display Music artists Albums and the relevant tracks and the tracks duration. Right now, I get the track duration like 00:03:26
but I want it to display 03:26
, so I made this MySQL-query where i use the SUBSTRING
-method:
public function artist_tracks_get($artist_id)
{
$this->load->database();
$sql = "SELECT products.title AS album_title, products.genre AS album_genre, products.ccws_pro_id AS product_upc, track_title, SUBSTRING(track_duration, 4) AS 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";
$query = $this->db->query($sql);
$data = $query->result();
if($data) {
$this->response($data, 200);
} else {
$this->response(array('error' => 'Couldn\'t find any artist albums!'), 404);
}
}
And inside my Backbone View I have:
serialize: function() {
var grouped = _.groupBy(this.collection.toJSON(), function(item) {
return item.album_title;
}), spanned = [];
_.each(grouped, function(item) {
var firstItem = item[0],
spannedItem = {
'album_genre': firstItem.album_genre,
'album_id': firstItem.album_id,
'album_title': firstItem.album_title,
'cover_image': firstItem.cover_image,
'digitalReleaseDate': firstItem.digitalReleaseDate,
'physicalReleaseDate': firstItem.physicalReleaseDate,
'pro_id': firstItem.pro_id,
'product_upc': firstItem.product_upc,
'tracks': []
};
_.each(item, function(albumItem) {
spannedItem.tracks.push({
'track_duration': albumItem.track_duration,
'track_title': albumItem.track_title
})
})
spanned.push(spannedItem);
});
return spanned;
}
When I run this query on my local phpmyadmin, I get the right result like 03:26
but when I test it online on my webserver, I get 00:03:26
... What is the issue here? Is it the SQL version? Is BackboneJs unable to handle the SUBSTRING
-method?
Please help! Thanks in advance...