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

April Wier
April Wier
978 Points

Confused by Quiz

I am at the php quiz where it is asking for php code to show the title in h1 tags. I am so confused by this. Why would you need php code for this? It doesn't make any sense to me. I'm not getting this and I can't get out of this darn quiz.

5 Answers

Elliott Frazier
PLUS
Elliott Frazier
Courses Plus Student 9,647 Points

You can use echo to insert statements in the middle of your code like this: when someone sends a message "message sent" will appear

if(isset($_POST["message"]){
    echo "Message sent!";
} else { .....

Or like this, when looping though an array it will echo out "the value is:" before every value so you don't have to type "the value is:" a thousand times

foreach($values as $value){
    echo "the value is:" . $value;
}
April Wier
April Wier
978 Points

Nevermind, I was missing the quotes. But seriously, why would you use php to do this instead of html?

Practice?

April Wier
April Wier
978 Points

Well, I certainly need the practice, ha ha. Is there any practical reason to do this? Would there be any benefit to using php to surround the html?

April Wier
April Wier
978 Points

Aaaaah! Thank you very much. That makes a lot of sense.

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello April,

I see you have solved your problem already but I would like to attempt to answer your question regarding the use of a server-side language such as PHP to emit HTML, as the challenge is requiring you do.

You would want to do this any time you have non-static pages. For instance, imagine the scenario where you retrieve several records from a database and you wish to generate an unordered list of items to display that data. Inside each of these list items you want to generate headlines and paragraphs for display.

You would use PHP to get the records from the database, loop through them and generate the list items, headlines and paragraphs for each one. Since PHP is server-side processing, all this happens on the server and is then sent to the client as one complete HTML document.

This is a very basic but incredibly common scenario. I hope I have interrupted your question accurately and have provided an answer that helps. If not please let me know and I'll try to clarify or embellish.