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

Databases

Jesse Thompson
Jesse Thompson
10,684 Points

What is the appropriate usage for arrays and databases on an ecommerce website?

Hello treehouse community. Right now I am learning javascript and I will be learning php after. I am studying up on the pros and cons of both languages and my goal as a developer is to learn how to build robust ecommerce retail experiences.

With that being said, I would like to determine what tasks are better left for javascript and what is better left for php. So for example, say you had a customer username system, that would obviously be better in a database but for products that can be added to a shopping cart, would it be better to use arrays or plug that into a database aswell?

edit: People have spoken about using nodejs for server side development but considering php is standard and theres enough people that speak out against using javascript for server side - much less javascript as a language - I want to do server side development right.

1 Answer

Chris Jones
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Jones
Java Web Development Techdegree Graduate 23,933 Points

Hey Jesse,

I haven't done much with JS, but I can try answering your question if you could explain what you mean by this statement: "So for example, say you had a customer username system, that would obviously be better in a database but for products that can be added to a shopping cart, would it be better to use arrays or plug that into a database as well"?

When you say "customer username system" do you mean a table in a database that has a column for username and a column for password?

When you say "but for products that can be added to a shopping cart, would it be better to use arrays or plug that into a database as well" are you asking if products should be stored in a database versus arrays in your application code?

Thanks!

Jesse Thompson
Jesse Thompson
10,684 Points

Yes Chris, I mean a username database that would store users and their information. Regarding the second part, yes I am asking which would be preferable. Right now I am thinking everything would be better in a database because it could remember the products you put into your shopping cart and you would be able to build a more intelligent backend with some analytics for products.

I am learning more as we speak, I think Ive figured it out but if you have anything to contribute back I would appreciate the advice.

Chris Jones
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Jones
Java Web Development Techdegree Graduate 23,933 Points

At a high level, you'll want to have a products table in the database. From there you can have a class in your application code that contains a collection of products - this is essentially the shopping cart object. When customers click a button to add a product to their cart then you add that product to the shopping cart's product collection.

At least that's how it was done at a high level from what I remember in the Java tech degree?.

I hope that helps you get a high level idea of how it works.