Interfacing php and mysql

Discussion in 'MySQL' started by jim_h, Feb 28, 2006.

  1. #1
    I'm trying to set up a php page that pulls an album title from a url parameter where the title has its spaces stripped and replaced with dashes i.e. /reviews/foo-bar when the title is foo bar. going to use modrewrite to point that to a page that will pull the foo-bar out of the url as a parameter and hopefully pull the corresponding review for foo bar album.

    I can't seem to get it to pull correctly, I've tried using fulltext searches and everything, any advice?
     
    jim_h, Feb 28, 2006 IP
  2. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Have you tried "like" with the wildcard % in the query?
     
    noppid, Feb 28, 2006 IP
  3. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Are you removing the - from the parameter before the query?
     
    mad4, Mar 1, 2006 IP
  4. jim_h

    jim_h Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i've tried using ereg replace to strip the dashes back out and replace them with spaces, hoping that i'd still be able to match titles when the original one had a dash in it. like for example one title is "def-con zero"

    so i run it throug a prep script that strips whitespace and replaces it with a dash for the url so that becomes:
    def-con-zero for the url.

    then on the detail page before the query i use magic quotes gpc and addslashes to clean it up, and use ereg replace to take the dashes out and replace with a space so it becomes: def con zero

    for some reason the match against returns an empty result every time. i tried using the LIKE %variable% but if the variable in the database has a dash somewhere in the text, since i strip them all out and replace with spaces, MySQL won't match them up.

    if it makes any difference ive tried writing the query two different ways to no avail, one using sprintf and placing %s in the AGAINST, and one using just a straightforward query using the $colname_albumTITLE in the AGAINST.
     
    jim_h, Mar 1, 2006 IP
  5. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I meant to say: replace the spaces with dashes and dashes with underscores.
     
    TheHoff, Mar 1, 2006 IP
  6. jim_h

    jim_h Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i would but the idea is to make the urls friendlier to search engines. if you have underscores in the title like albums/def_con_zero it takes def_con_zero as one word, to my knowledge at least. so i'd like to use dashes if i can in the urls and then somehow clean it up so that i can pull from mysql based on that.
     
    jim_h, Mar 1, 2006 IP
  7. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Always use dashes rather than underscores in my experience.

    The names in the database need to be free from dashes to start with and then you use
    $var= str_replace(" ", "-", $var);
    PHP:
    to add the dashes and the opposite to remove them.
     
    mad4, Mar 1, 2006 IP
  8. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Well, that is the issue- they're not free from dashes as they are proper names of artists, right? When I run into this problem, I just bite the bullet and use underscores for the dashes and dashes for the spaces. That way, most names (without dashes) are rendered as intended.

    I'm of the opinion now that a keyworded filename doesn't make that big of a difference when compared to other factors. Also, you can regularly see keywords highlighted in the results pages that are not separated properly.
     
    TheHoff, Mar 1, 2006 IP
  9. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I just remove all dashes and brackets etc from the names and make them plain text.
     
    mad4, Mar 1, 2006 IP
  10. jim_h

    jim_h Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10

    That's fair enough and I also tend to agree. I guess I'm split between making the urls more friendly to search engines (as opposed to have them turning their noses up at url parameters), and also friendlier and more memorable to my readers. albums/def-con-zero is certainly easier to remember than albums/32.

    I think I'm going to do a little more probing of mysql to see if theres SOME way I can get them to match with a query otherwise I'll just leave it as is now. Thanks for your input and I'll definitely experiment with the methods you guys have suggested so far
     
    jim_h, Mar 1, 2006 IP