SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: how to do it

  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    how to do it

    hey folks,
    i m new at databases and stuff. haven't read them after university so i m making page which have songs. i got the songs list.. but i don't know how to get information about the song like genre,ratings and stuff from other table i created. coz its like when the person clicks the link. he is send to another page and there the related song information is showed. how should i be doing it. joins or what?
    All those who wander aren't lost.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    I don't know. What does your database look like? What data from which tables do you want to show?

  3. #3
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i have one table with id,artist,song,length,run time and i was thinking to make another table for storing pictures of that song. or perhaps do it in the same table?
    All those who wander aren't lost.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    More than 1 picture per song? A different table.

    No need for the album name? If you do, then you'd make a new albums table, move the artist from the songs table to the albums table, and add an album_id to the songs table.

  5. #5
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i'll see that though i am having hard time imagining. when a person clicks on a song and he is taken to the song page. how should i do the query.? get album_id on same page 1 and all the info about the song. put them in variable and post to it to the next page? (ofcourse the query on page of getting info about song won't be displayed on page 1 but on page 2)
    All those who wander aren't lost.

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    The albums table was just an idea. If you don't need it, forget about it. Let's not complicate things too much

    What you need to send to page 2 is the key that identifies the song that the user has clicked. I guess that would be the id from the songs table.

    So you'd have a link on page 1 like
    Code:
    <a href="page2.php?id=1>a beautiful song</a>
    And in page2.php you'd get the id from the query string ($_GET['id']) and use that in your query after sanitizing its value to get all the song info.
    If you need to get the images from the songimages table as well, then you'll have to join the songs table and the images table.

  7. #7
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    The albums table was just an idea. If you don't need it, forget about it. Let's not complicate things too much
    actually i do need it coz when album is clicked it shows album page
    All those who wander aren't lost.

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Ok. So you'd send the song id to the songs page, and join the songs, albums and songimages tables to get all the info for that song you need.

    Similarly, you'd send the album id to the albums table (when an album is clicked), and join the albums and songs tables to get all the info for that album you need.

    Attention though: since an album can contain more than 1 song, joining the albums table to the songs table based on an album id will give you multiple rows with the album info duplicated. You'll have to write your code to manage that situation.
    The same goes for the join between the songs table and the songimages table.

  9. #9
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hmm sound hard. but will get there i hope.
    All those who wander aren't lost.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •