Jump to content

URL rewrite with mysql and php


zerodefect

Recommended Posts

I have a database of mp3 players where viewers can view the specs of particular players.

 

Each player naturally has a 'Manufacturer' and 'Model' table associated with a 'Player'. This is depicted in the attached diagram.  Players stats are received on the web via a GET on the players id (Players_pk) like http://www.example.com/compare-players/?id=1

 

What I would like to be able to do is to make the URLs friendly of the form:

http://www.example.com/compare-players/sony-nwz-s540

 

To break the problem down, I thought it would be best to start retrieving a player via its manufacturer and model with a regular GET: http://www.example.com/compare-players/?id=sony-nwz-s540

 

The problem I have is that the db contains models that have a name with non-alpha-numeric characters.  Ideally, I would like to deal with the parenthesis and the like - something like "Apple iPod (3G)" would become "apple-ipod-3g". I could always store the URL friendly player name (like sony-nwz-s540) in the db itself, but what happens if I would like a different permalink structure?

 

I am feeling rather stuck, and I think I need some guidance.

 

Any tips/recommendations would be much appreciated...

 

zerodefect

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/187329-url-rewrite-with-mysql-and-php/
Share on other sites

Personally I think I'd do what you suggested yourself. Create a small script to add a field to the database (permalink) and then populate it using a function that will strip all unwanted characters from the model_number field of the db. What do you mean by 'what happens if I want a different permalink structure'?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.