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

General Discussion

Scott Moore
Scott Moore
4,050 Points

Product filter and search for my website.

Hey all, heres a couple questions. First off, I'm not even close to doing it yet, but its on my list of things I want to accomplish and eventually put on my website. When you go to say Best buy or Ebay or Amazon or sites that sell items.

When you click on Best Buy say TVs. How is that site accomplishing showing all the items listed? Are they doing it though JS or Jquery, PHP Ruby or are they just adding some kind of an element to the html to take you that section? I would like to have that type of option and not sure what path I need to venture down.

Also, these sites have a search bar also. So if I am in the search bar and I type in Derek Jeter rookie baseball card. How does the site know to show people who are selling those cards. What kind of programming are they doing?

Again something I would like to offer on my site eventually. I may not even need the search function. But I know I will eventually want to have that drop type menu that best buy offers so people can go to the particular category they may be looking for.

Any insight of how that is accomplished would be great. Thanks.

1 Answer

Thomas Prince
Thomas Prince
23,302 Points

I've never done this from scratch, but I implement e-commerce sites with wordpress and woocommerce at work, which has this functionality. So, I think we're talking about php making queries to a mysql database in my case, which thankfully wp and wcom handle for me.

Based on my limited experience dealing with databases, products are listed in tables. Each product has its own row. Columns are used for product attributes (quantity, price, category). Something like this:

    Table name: products
id    |     name     |     category
0     |     ring        |      jewelry
1     |     doll        |      toy
2     |  necklace   |      jewelry
3    |  jeter rookie | baseball card

A sql query of this database would look something like this(Although this might not be correct sql. It's been a while.):

select * from products where category=toy;

This returns all entries from the table "products" where the category attribute === "jewelry".

PHP, ruby, and I assume any backend language have methods/functions that you use to make these queries to the database, usually something like query('select * from products where category=toy;')

SO, whether you're clicking links or typing in a search box, a query to a database is made and a page is generated based on those results.

All that said, I'm definitely new at this stuff, and it is most definitely more complicated than this, so you've got more research ahead of you. Hopefully someone else will give you a better answer. Good luck.