Simple PHP question

Discussion in 'PHP' started by absentx, Nov 3, 2011.

  1. #1
    Basically looking for the best way to handle a situation like the following:

    I am coding a small website that for the most part really has no needs for a database unless I want to put that time in so I can make a simple CMS.

    I have about thirty frequently asked questions to put up on the site, and I want to reference them by id. What is the most correct solution in terms of how this should be coded?

    A. Make a database table and list the FAQ answers each having a unique id (already said I dont feel a need for a db for this site, but this is a possible solution).

    B. Just make a script that holds all the answers and use something like a switch statment on the id variable to pull the right answer.

    My thought is by the time I get done setting up a new db and coding the stuff for that, I am just as good using the switch statement or similar.

    I am interested in what is the best and most correct way in terms of speed and proper coding.

    Thanks!
     
    absentx, Nov 3, 2011 IP
  2. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #2
    Both those ways would work, I'd use the database - makes it easier to add answers and doesn't mean as much code as a switch statement etc. Probably not the most efficient thing to use for something of this small size though.
    Better than switch would probably be an array:

    
    $answers = array(
        '1' => 'Answer 1',
        '2' => 'Answer 2'
    );
    
    PHP:
    And use foreach to get each one.
     
    blueparukia, Nov 3, 2011 IP
  3. absentx

    absentx Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Just the kind of answer I was looking for, thank you.

    also just found out that client might want some customizable features in the future, so I think we just got our database anyways, I appreciate the feedback.
     
    absentx, Nov 3, 2011 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #4
    Any decent hosting company will provide you with the database and they're so easy to use I'd avoid the text file automatically.
     
    sarahk, Nov 5, 2011 IP