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

How do I present different data in same layout efficiently?

So I'm trying to work out the logic of a project here (I'm a beginner).

Here is a simple example.

I have one main page with 5 buttons. (Alex, John, Bob, Max, Lauren)

Click on a button will lead you to their profile page with information containing their "Full Name, BOB, Description etc,)

What I am trying to understand here is Alex, John, Bob and the rest have the same profile layout but with different information.

How do I make code more efficient sp that I can input their data in the same layout/template without having to create a new file, copying and pasting code every time I add a new person or name?

Can you lead me to a specific tutorial on Treehouse?

1 Answer

Kevin Korte
Kevin Korte
28,148 Points

You will want to look into organizing your web page with a MVC approach. MVC stands for model, view, controller.

This would be a great task for just very basic PHP, and you can learn how to do this in the PHP lessons here.

Basically, your view will be your layout with variables where the data for each user will go. Your model would store the data like the name, bio, etc, and your controller will fetch the correct model and give it to the view to be rendered on the browser.