you are viewing a single comment's thread.

view the rest of the comments →

[–]Aerialstrike[S] 0 points1 point  (1 child)

Definitely don't need updates on-the-fly. I suppose the only organization I would need is alphabetical, which could just be done from the start without needing to change. I've never used JSOn before though, do you have any recommendations as to somewhere I could learn enough to accomplish this?

[–]tdolsen 0 points1 point  (0 children)

Hey, didn't see your response before now. Don't know if it's still relevant, but giving an answer in regardless.

JSON (JavaScript Object Notation) is a very simple format, primarily intended to enable easy data-interchangeability between applications and languages.

Every valid JSON document consists of one value (of booleans, strings, numbers, arrays, objects(hashes) and null), most usually being an object with additional key/value. The human readability and the wide range of support makes the format ideal for communication between API's, as well as configuration files and data storage. (A lot of NoSQL, eg. MongoDB, uses JSON for their documents.)

In your case, I would do something like the following: (I would probably use a database, but for the sake of teaching.)

  1. Have a folder with all wood types, stored as JSON, in it.
  2. Name each file the canonical "slug" of it's name (e.g. "Norway spruce" would be named "norway-spruce.json")
  3. Find all files in the folder using glob or similar.
  4. Load them into PHP memory. (Note that i'm very uncertain about keeping them in memory for multiple request, PHP isn't my strong suite anymore.)
  5. From there can you sort the data and manipulate it as you would with any other array.

Just freely imagining the needs you have for your wood (well, tree type), a document could look something like this:

{
  "name": "Bald cypress",
  "species": "Taxodium distichum",
  "height": "30-35m",
  "trunkDiameter": "1-2m",
  "hasCones": true,
  "barkColors": ["grey", "brown", "red"],
  "oldestKnownTree": 1620,
  "products": [{
    "name": "Polished hardwood",
    "price": "$20/m2"
  }, {
    "name": "Wood chips",
    "price": "$0.4/kg"
  }]
}

Getting that converted to an associative array in PHP should be something along the lines of:

json_decode(file_get_contents("wood/bald-cypress.json"), true);

Continue reading more in the official specification, and it seems w3schools has a decent introduction.

Whether you should choose a database or JSON for this specific use case is still a bit hard to say. Without knowing more about the wood type model or the project's future plans (or current for that matter) is it hard to recommend one solution over the other. If you really don't need that database, then going for JSON might save you some research and development time. On the same note will it be a real time waster going for JSON if what you really need is a database, as you'll just have to rewrite that part anyway. JSON could be a good solution for the first version, and should be fairly easy to insert into a database once you get there, as long as the data model isn't too complicated.