SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File or Database for storing repetitive terms/phrases?

    A website I work on is rapidly getting larger. I'm finding I have the need to store variables for labels, snippets of code and just any repetitive text because some of them are exactly the same wherever they are used and can be on up to 200 pages. For speed purposes (or any other concerns) is it better to just store them in a file with a bunch of variables set or in a database? (using PHP and MySQL)

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Madison, WI
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you would never want to store that info in a database...the extra query on each page would slow down (albeit marginally) your load times...

    my recommendation would be to just define everything in something like vars.inc or config.inc like so:
    PHP Code:
    define('VAR1','Hello');
    define('VAR2',' World!'); 
    then include it on each of your site's pages and use the vars:
    PHP Code:
    <?php
    include('/path/to/vars.inc');
    echo 
    VAR1.VAR2;
    ?>
    i like to use define because then i don't accidentally assign a different value to a variable name on an individual page

  3. #3
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using a constant is a good idea. I was thinking variable but these values won't be changing. Just one more thing- most of these constants are a few words or a sentence or two. Would it still make sense to use a constant if the constant was a section of HTML code that was like 7 to 10 lines long? Or should that get it's own separate include file?
    Last edited by frankdux; Nov 22, 2004 at 14:34.

  4. #4
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To be more specific, if my there was a section of HTML code that gets repeated very often like this: (or it could possibly be an even longer section of code):

    <tr>
    <th>Description</th>
    <th align="center">Part Number</th>
    <th>Quantity 1-9</th>
    <th align="center">Qty 10 or more</th>
    <th align="center">Shopping Cart</th>
    </tr>

    .... would it be best to store it as a constant in one file with many constants OR in it's own separate file? I hope I've provided enough information.


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
  •