Jump to content

[SOLVED] Advice on rewrite, artistId/songnameHash/ or artistHash/songnameHash/?


limitphp

Recommended Posts

To get to the comments page of a certain song, should I rewrite the url like:

website.com/artistID/songnameHash/

or

website.com/artistnameHash/songnameHash/

 

ex)

www.website.com/2/The-Weight/

or

 

www.website.com/The-Band/The-Weight/

 

The only reason I would do the first option is because, the artistID is stored in the song table, so I wouldn't have to make two trips to get the artistnameHash.

 

I figure most people will never type it in manually...they'll just follow the link.

 

What do you think?

 

 

Link to comment
Share on other sites

you should  be able to join the tables and make it in 1 query. i would use the artist name vs the artist id to make it more SEO friendly

ok.  I'll use the artistNameHash.

 

I didn't even think of how I'm going to get the songID from the song table.

 

I've never used a JOIN before.  What it be a left join, right join or just a join?

 

In my songs table I have the columns:

songNameHash

songID

artistID

 

In my artist table I have the columns:

artistNameHash

artistID

 

with songnamehash and artistnamehash coming from the query, how would i get the correct songID?

 

thanks

 

 

Link to comment
Share on other sites

SELECT * FROM songs s LEFT JOIN artists a ON s.artistID = a.artistID WHERE s.songNameHash = '$songHash' AND a.artistNameHash = '$artistHash'

 

but then again...is songNameHash unique across the entire song table? if so, then you can use just that in the where clause

Link to comment
Share on other sites

SELECT * FROM songs s LEFT JOIN artists a ON s.artistID = a.artistID WHERE s.songNameHash = '$songHash' AND a.artistNameHash = '$artistHash'

 

thank you so much!

 

why a left join and not a right join?  I'm really trying to understand this, but JOINS really confuse the heck out of me!

 

I'm reading about them,

    *  JOIN: Return rows when there is at least one match in both tables

    * LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table

    * RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table

    * FULL JOIN: Return rows when there is a match in one of the tables

 

 

but I can't seem to understand it fully....

 

 

 

Link to comment
Share on other sites

so, a normal JOIN should work too...the only difference you would see is if there was a song with an artistID that wasn't in the artist table. the LEFT JOIN will return that song even if there is no matching artistID in the artist table

 

This might sound stupid, but how do you know which table is the left one and which one is the right one?

Does it come from this part?:

ON s.artistID = a.artistID

 

after the ON, the one on the left side of the equal sign is LEFT, and the one on the right side is the RIGHT one?

Link to comment
Share on other sites

so, a normal JOIN should work too...the only difference you would see is if there was a song with an artistID that wasn't in the artist table. the LEFT JOIN will return that song even if there is no matching artistID in the artist table

 

I want it to match where artistID is in both.  There will never be an occasion where its not in both....

so, would I use JOIN or INNER JOIN?

 

nevermind.....they are the same.....I just found out....

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.