[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PHPwestoz] [OT] Relational SQL Databases



Ok. I wasn't sure how to do relational stuff. As Evan said I don't need
innoDB to do this.
What would be the INSERT command that would insert the ID with out
needing a separate SELECT? Basically I don't want to do 2 SELECTs to get
the Artist and Album ID's for my INSERT for each song.
Along that note how can I do INSERT if not exists?

TIm,

I don't quite understand what you mean. To insert a new song, you first need to know which album it will belong to, and that will automatically link it to the right artist. You can either do this by hand as you populate your MySQL table, but that is a bit awkward, or you can create a little interface that shows you all available albums in a <select> menu. You can then pickup the ID number associated with that select element, and create your Insert statement from that : INSERT INTO Songs (`Song`,`AlbumID`) VALUES ('$song', '$AlbumID')

If the album is a new one, not yet in the database, you'll have to create it the same way you created your song, but link it to an Artist instead. If the artist is also new, you'll need to start by creating the artist.

I hope that answers your question..