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

Riki Tiilikainen
Riki Tiilikainen
4,042 Points

How to display the best value items on my homepage?

In PHP I want to select items from a database and then only display the items that are below a certain price point. I know how to select the items and display them, but unsure how to segment the data based on price. Any suggestions?

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Riki Tiilikainen ! I might suggest altering the SQL from getting all the items into an SQL statement that sorts by price in ascending order and then limit the results to the set that you want.

So something like:

SELECT column_name(s)
FROM table_name
WHERE condition
LIMIT number;

I'm not sure if you're using an ORM for this or not, but if you are you will need to see their documentation for how to set the condition and the limit.

Hope this helps! :sparkles:

Riki Tiilikainen
Riki Tiilikainen
4,042 Points

Thanks Jennifer, That gives me an idea, I probably need to select items within a price range.