Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Kevin Korte
Kevin Korte
28,148 Points

Do I need a database...yet?

So I'm working on site and I'm conflicted about which way to go. Here is what I have going on.

I'm a gearhead, too. I'm really good at finding parts, cross-referencing part numbers, finding what fits what doesn't, and finding solid technical data like torque values, clearances, etc.

I want to build a website for a certain type of machine, that for each year, make, and model I list out common lubricants, various brands of filters, and other parts, and technical service data.

Phase 1 is just getting 100 or 150 machines done and the site launch, simply to just display the data.

I can't decide if I should place this data in a database (it isn't really going to change) or if I should just use an MVC architecture and put the data in a PHP multidimensional array, and loop through to display the values.

Phase 2 would be to allow multiple machine data sheets to be shown in comparison side by side, search feature, etc.

Phase 3 would be a log-in user account feature where a user could add vehicles to his "garage" to quickly save and recall the page without having to find it again. (I know for sure a database would be needed at this point)

Phase 4 Allow users to create a maintenance log and store lubricant types, part numbers for easy reference, and have a digital record of what maintenance they have done and when they did it. (Again, this will need a database).

So, not knowing much about databases at the moment, do I mess with setting one up now, or is it unnecessary for simply displaying these values to the screen, and use arrays like Randy did building Mike's T-shirt website?

Any advice appreciated. Thank you.

7 Answers

Yes. Anytime you will be storing data, you want to make sure it's in a persistent fashion such as a MySQL database. This makes it very easy to create, read, update, and delete any data. This also gives you the ability to query everything in your database, providing basic search functionality. Something that would be a lot harder to implement with arrays and such. Databases are so incredibly popular, because they are necessary, which makes them pretty easy to incorporate as well.

What I really recommend(beyond all of this), is moving along to a content management system (CMS). Learning how to program a website from scratch is liberating, but it is impractical when you have to make consistent updates on the website. A content management system will allow you to have others people to log in to add/edit content, quickly add new posts/pages, implement pagination and much more. I would recommend a simple CMS like WordPress.

Kevin Korte
Kevin Korte
28,148 Points

Ernest,

Thanks for your thoughts. Given that the data would only be set by me, static, and not changing....I was wondering if a database at this moment was necessary. I have spent the last two days setting up a basic MySQL database to query against, and am up to date on Andrew's database classes. I've spent a lot of time looking at how wordpress or drupal sets up a database and stores information, but it's typically information that is constantly created, updated, read, or deleted. My info to start will just be created, and then read. It won't hardly ever change. I would have thought searching for info would have been a big plus, but randy made it appear easy to search for information when it's only stored in an array.

On the topic of CMS...I have a working prototype of Wordpress, Drupal, and Media Wiki installed locally. So far none of these have provided exactly what I've been looking for. I have also looked at Joomla, concrete5, and expression engine. Those haven't shown me a great way to enter in just raw data values.

With wordpress, I've up to date on Zac Gordon lessons, I've messed around with custom post types, but the only way I've found it to work is still to enter html into wordpress's page box, and it seems like a lot of bloat to still be typing HTML. Drupal is the same issue so far, and Media Wiki just isn't what I want. There could still be something I don't know yet to find my solution with a CMS.

WordPress will create all of your database info for you. I recommend for each product you create a "post". This is how a lot of websites are set up. Each post is a product/flash game/post. With WordPress, once you set up your database in the beginning, you never really have to touch it again.

Again, if you only have 5-10 products I recommend sticking to the route you're currently on. When it comes to ease of use, WordPress is the way to go. I can setup a website that would meet your needs in less than 15 minutes with WordPress. Adding all of the "machines" would take a little bit, but I still feel that just trying to accomplish this by yourself using arrays is overkill. Again, this is my opinion and from my personal experience. My first website I set up was very similar to what you are doing. After struggling to maintain it after about 3 months, I moved over to WordPress. Randy has some very good points, but again I believe that having anything over 10-20 entries is a little overwhelming to just do yourself.

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

Ernest has some good points, too! Three last things to consider:

  • If you have 150 products in an array and someone says, "Let's add two new fields to every product," you'll wish you had it in a database.
  • How soon do you need to finish Phase 1? If you don't have any idea how to use the technology (whether it's a database or WordPress) and you need this completed sooner rather than later, then I probably wouldn't let that hold you up.
  • WordPress is great for lists of content, but creating relationships between the different content types (including maintenance logs) can require a lot more customization. To get it where you want it at the end of Phase 4 would probably require you hiring someone with that kind of experience.
Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Hey Kevin,

Using an array is just fine; I would stick with that for as long as you can. Adding a database adds complexity and one more point of failure. I put together a list of things that would make me switch it to a database; it sounds like you can wait until Phase 3 in your case to switch.

Even if you use a database, I would recommend the MVC architecture we have in place. The next thing I'll cover in the PHP course is how to put the data in the database, and we'll stick with the same architecture. We'll change the functions in our model to get the data out of a database but, all the other code will remain the same. That's the beauty of separating concerns like we've done: you can't complete change how one of the concerns works (moving data from an array to a database) without affecting the others.

I would switch to a database for any one of these:

  • If non-technical users need to change the data
  • If the number of products grows to a point where the making changes the array are too hard to make (what counts as "too hard" is completely relative to your threshold for pain :-) )
  • If you need to store data that relates products to each other or to other types of data (companies, categories, etc.)
  • If you need different data in multiple environments (like development, test, stage, and production environments)

I'd stick with an array until you really have to switch.

Kevin Korte
Kevin Korte
28,148 Points

I'm quite comfortable getting wordpress set up. Currently, I have a bootstrap theme set up that I've been playing with. Adding info about the machines is just going to suck, I know that. No matter how I do it, it's dirty work that has to get done.

Where I struggle in choosing a path is that hundreds, and eventually thousands of machines with different data types. My goal is to go through all of the ATVs, side by sides, watercraft and snowmobiles for all the major brands over one or two decades of machines and models. It'll end up massive.

Initially, I'm starting much smaller, and picking 100 or 150 machines I know well, and already have technical service docs on.

Phase 1 has no time frame. The sooner the better...but I'm doing this for me, not anyone else.

After all this discussion, it boils down to this I think:

Many machines, are going to share data values and part numbers, but all will be unique and various things will change. I need to be accurate and reflect that.

Do I go through the machines one by one and look up and enter their data for that machine....OR...somehow have a database of all the air filter part numbers I've used, what machines that part number fits, and somehow associate that air filter number to that machine. (I know how to do the first way, I'm not sure how to do the second way)

Then end result though is that someone goes to:

For example: www.mysite.com/type/year/make/model

and sees something like this:

  • Filters:
  • OEM Air Filter: [Part number]
  • Brand A Filter [Part number]
  • Brand B Filter[Part number]

<br />

  • Lubricants:
  • OEM oil [Type - PN#]
  • Coolant Type: [Type]

<br />

  • Torque Values:
  • Head bolt: [Torque]
  • Lug nuts: [Torque]

...and so on.

Some machines will have more info on them than others. I've been able to get wordpress to work by entering both table and list item tags. But I feel dirty typing in html tags with my values into wordpress post or page boxes to get it to display correctly.

Also brings me to a side note. List items or tables for this data? I know tables for layouts are a bad idea, and generally avoided...but I don't know about this. Twitter bootstrap has decent looking styles and features for table data.

Really appreciate the feedback so far. I've been mulling over this for a week now.

Kevin Korte
Kevin Korte
28,148 Points

I'll add, something else I've been playing around with in addition to a CMS like wordpress is a framework. I've looked at Zend, Cake, and Codeigniter.

Codeigniter's docs made the most sense to me the fastest, and so that the one I downloaded and installed to see what I could do with it in what amount of time.

Thoughts on this over a CMS like wordpress?

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Your choices are really between something like WordPress and something like CodeIgniter. (I don't think I would try to build something like your Phase 4 from scratch.) When comparing WordPress to something like CodeIgniter for a project like this, it's best to think of WordPress as a sample application built on a different framework. WordPress has quite a lot of features already built. If they are the features you need, you can save a lot of time by building on top of it. But if you need features that aren't there, you are going to have to build them custom -- and WordPress isn't exactly built for you to easily add lots of new core features. WordPress will give you a lot of lift, but you may end up spending more time fighting against it by the end than if you had just built it all custom on a framework.

The big question is how much the site you want to build already like a WordPress site. WordPress has a good interface for editing content already built. On the other hand, I've built WordPress sites with web addresses like this before ...

www.mysite.com/type/year/make/model

... and that's just not that easy to pull off. You have to work within WordPress's rewrite rule API, which can be harder to manipulate than creating custom routes in a framework.

Kevin Korte
Kevin Korte
28,148 Points

Yes, that's been my frustration juggling these two paths to go. If I ever get to phase 4, I'll need some money, and I'll need some help. I might never get there, and that's okay. But, I need something massive to shoot for. Other than that, do those steps sound logical? I'm trying to buy time to learn more. 3 months ago I knew nothing about MVC, databases, or CMS's. I didn't even know enough to ask this question.

My only problem with a CMS is I still don't see a way I can use it without writing basic HTML in the post box to structure the data how I want it to appear. The nice feature of being able to edit it later, have comments, etc I wont really need. Very rarely will this data need be changed once it's written. Torque values or oil weight recommendations from manufacture do not really change.

Because each machine is unique in it's own way, I don't every see a scenario where I need to add the same value to all machines. I would still need to check that value to each machine to ensure accuracy, which is again where my database vs. array question came from.

I'll kick it around a little more. I'm more comfortable with arrays then databases, so I'll probably start with looping an array. Maybe just start with 20 machines and than re evaluate if I want to switch to a full CMS for some features I didn't think about.

Thank you both Randy and Ernest. You guys have given me a lot to think about.

Two quick questions if you don't mind:

1) Tables vs. lists for displaying this data in a structured and linear fashion...thoughts?

2) Are there any performance issues with large arrays? Say I have 300 values in a multidimensional array, is the code going to have problems executing?

Kevin Korte
Kevin Korte
28,148 Points

After much thought I'm going to go the wordpress way, and just bootstrap a simple theme based on some of Zac's lessons in the WP Theme development area to start. I'll work slowly on using bootstrap to make it unique to my site. I'm doing this because if I grow out of wordpress as a CMS, I'll be able to get my model code back out of it, and rebuild some other controller and view code or CMS that will work better.

In the meantime, using wordpress will get me features like search right off the bat...and I'll be able to continue to add data and update the site from any computer if I'm traveling, not just my specific laptop.

Again, THANK YOU both. I actually feel much better.

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

That seems like a reasonable approach. Glad to have been a help!