3 Replies - 251 Views - Last Post: 21 May 2013 - 07:06 PM Rate Topic: -----

#1 adn258  Icon User is offline

  • D.I.C Addict

Reputation: 11
  • View blog
  • Posts: 762
  • Joined: 31-August 11

Is It Better To Use Of Enums Arrays, Or Reference Tables For Set Data?

Posted 21 May 2013 - 03:49 PM

So when you have something users can choose where there is a set limit for instance colors, cities, continents etc. I hear many people complain rightfully so about using a ENUM column type in MYSQL. I have known people to use reference tables for this problem before, but many times I find myself simply using a static array.

What's wrong with this? I have an array I can readily change for example cities and those are all output in a drop-down menu to the user. Then to check and make sure the user isn't injecting their own custom values somehow I always just use in_array to check. Both on data input and data search results. This seems faster especially for smaller arrays.

Which method is better? Is using arrays for this acceptable or advantageous? What are the advantages and disadvantages of each approach?

Is This A Good Question/Topic? 0
  • +

Replies To: Is It Better To Use Of Enums Arrays, Or Reference Tables For Set Data?

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2984
  • Posts: 10,316
  • Joined: 08-August 08

Re: Is It Better To Use Of Enums Arrays, Or Reference Tables For Set Data?

Posted 21 May 2013 - 05:03 PM

Which ever is easiest to manage is better.
You might use a text file:
<?php
$states=file("states.txt");
print_r($states);


states.txt:
Alabama
Arkansas
Connecticut
Delaware



This way any authorized user could update/change the file without affecting the code.
Was This Post Helpful? 0
  • +
  • -

#3 adn258  Icon User is offline

  • D.I.C Addict

Reputation: 11
  • View blog
  • Posts: 762
  • Joined: 31-August 11

Re: Is It Better To Use Of Enums Arrays, Or Reference Tables For Set Data?

Posted 21 May 2013 - 06:43 PM

Never thought about that either. Essentially what you're saying is a lot of programming problems don't have a de facto method for solving the issue at hand.

This post has been edited by Dormilich: 21 May 2013 - 10:39 PM

Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2984
  • Posts: 10,316
  • Joined: 08-August 08

Re: Is It Better To Use Of Enums Arrays, Or Reference Tables For Set Data?

Posted 21 May 2013 - 07:06 PM

In life there are usually many ways to accomplish a task. Programming too!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1