SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Which would be more efficient? db field with value or change on the fly?

    I am making an arcade script to use on my arcades and one of the requirements I set myself was to get the site as fast and efficient as possible.

    In my script I change game names so that they can be used in urls (example: Age Of War becomes Age-Of-War).

    Now my question is, is it better to do it as I am by using str_replace(' ','-',$row['Name']); or would it be better if I created a field in the database with these hyphenated names in , saving php from having to alter them on the fly but requires an additional field to be read from the db.

    I know this maybe taking it too far and it probably works out that the effects cancel each other out and make any speed gains worthless but I have lots lots of games and I figured that while the effect on one maybe nothing, the effect on 1300+ maybe worth looking into.

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2008
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've definitely got the idea, and no its not taking it too far at all, actually I'd take it a step further. Store the title in the db as 'Age Of War' and call the url as so
    PHP Code:
    str_replace(' ','-',$url);
    strtolower($url); 
    Now the url is all lower case, perhaps a bit safer url. Depending on how you set up your mod-rewrites and application, it may be easier to do this in reverse. Store the slug in the DB name, however you'd lose the ability to decapitalize words (without a bit more strain) such as 'of', 'and', etc/

  3. #3
    SitePoint Evangelist praetor's Avatar
    Join Date
    Aug 2005
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll go with the db field. It's computed once then you can use it as is every time.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you both for the suggestions and input, I thought that a db field would be better but I wasn't sure. If anyone else has any input or recommendations I would be very grateful to read them.


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
  •