laanes Posted May 11, 2011 Share Posted May 11, 2011 Hi! I would like to create values for album_id field, so i can link songs with albums. Since there is a big number of songs and albums, I was wondering whether there is a better way to create those id's than going through each song manually? Can you point me to the right direction or share any thoughts about this? Greetings, laanes Quote Link to comment https://forums.phpfreaks.com/topic/236135-creating-values-for-album_id-field-to-link-songs-with-albums/ Share on other sites More sharing options...
requinix Posted May 11, 2011 Share Posted May 11, 2011 What are you talking about? Quote Link to comment https://forums.phpfreaks.com/topic/236135-creating-values-for-album_id-field-to-link-songs-with-albums/#findComment-1214062 Share on other sites More sharing options...
laanes Posted May 11, 2011 Author Share Posted May 11, 2011 Sorry for not being clear enough. I would like the group the songs somehow for searching by album. So i have created table albums with id, album_id, album. Then i imported the albums from a textfile so that the id field got filled with auto incrementing numbers and albums field with album names. album_id didn't exist in the textfile so it got filled with 0's. I'd like for example song 1-9 to have album_id 1, song 10-19 to have album_id 2 etc. How could i accomplish this? Quote Link to comment https://forums.phpfreaks.com/topic/236135-creating-values-for-album_id-field-to-link-songs-with-albums/#findComment-1214100 Share on other sites More sharing options...
requinix Posted May 11, 2011 Share Posted May 11, 2011 If you have an id field already then what is album_id supposed to be? Quote Link to comment https://forums.phpfreaks.com/topic/236135-creating-values-for-album_id-field-to-link-songs-with-albums/#findComment-1214104 Share on other sites More sharing options...
laanes Posted May 11, 2011 Author Share Posted May 11, 2011 id is an auto incrementing integer just for a way of sorting the records. Quote Link to comment https://forums.phpfreaks.com/topic/236135-creating-values-for-album_id-field-to-link-songs-with-albums/#findComment-1214112 Share on other sites More sharing options...
requinix Posted May 11, 2011 Share Posted May 11, 2011 Auto-incrementing fields shouldn't be used for any other purpose than identification. I'm wondering about album_id. If that's what you meant when you said id is an then my next question is "Why not sort on whatever thing you actually want to sort by? Like date or name or something." Quote Link to comment https://forums.phpfreaks.com/topic/236135-creating-values-for-album_id-field-to-link-songs-with-albums/#findComment-1214151 Share on other sites More sharing options...
laanes Posted May 12, 2011 Author Share Posted May 12, 2011 Hmm, yes, i can see what you mean. But how would i get all the songs related to the album i searched for? Since the AI id is unique to every row, it means i can not link songs to albums like this? : "SELECT album, song FROM albums INNER JOIN songs ON albums.id = songs.id" I'd like to get all songs from the album "raccoon" for example. Quote Link to comment https://forums.phpfreaks.com/topic/236135-creating-values-for-album_id-field-to-link-songs-with-albums/#findComment-1214341 Share on other sites More sharing options...
requinix Posted May 12, 2011 Share Posted May 12, 2011 SELECT ... FROM songs JOIN albums ON songs.album_id = albums.id The albums table doesn't need a second ID field. One is plenty. Quote Link to comment https://forums.phpfreaks.com/topic/236135-creating-values-for-album_id-field-to-link-songs-with-albums/#findComment-1214566 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.