dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: How should I handle my database

  1. #1
    Join Date
    May 2017
    Posts
    27

    How should I handle my database

    On my website, I have items I need all in 1 list (grab from a single table), but each category of items has its own larger subset of variables (20+). Should I make a slot in the table for every variable, or should I use an array to hold all the variables in 1 column of the table? I feel that the latter would be better (single column for an array), but was not sure on how it would affect insert/select (and how to actually grab it as a variable and not string).

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,214
    There are a number of "it depends" that might affect the decision.

    Generally, the rules of database normalization would be against that, stating that each field should contain only one item of information. The solution in a relational database might be to have a separate table that you join with the primary table. This would allow for multiple rows of data in that relational table to be linked to one row of the primary table.

    Now, if that data is only ever going to be retrieved but never searched against, you could probably get away with making it a text column and storing, perhaps, a JSON string that you could use in your application when you retrieve it. But that is going against the usual "rules", so I'm hesitant to just say go ahead and do that without really understanding what that data is modeling and how you want to use it (and might want to use it in the future).
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    May 2017
    Posts
    27
    It is most certainly information I have to search from.

    Is this where I would use the "relationship" tab on phpmyadmin? (I tried using it before, but it said that the connections feature was disabled.)

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,214
    Afraid I don't know how to do it via PHPMyAdmin, due to working mainly in PostgreSQL these days, plus that I'd just build the table directly.

    You'd probably have a column that is a foreign key to the main table, and a column with the actual data. You might optionally have another column used to indicate what type of data it is -- which could be an enumeration type, or even be a foreign key to a third (generally static) table that you use to store the data type information.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center