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

Development Tools

seems as though im stuck on this too

Select the first letter of the "first_name", followed by a period, followed by a space and then add the "last_name". Also, convert "last_name" to upper case. Alias it as "name". Here's an example: "A. CHALKLEY". The name of the table is "users".

2 Answers

Codin - Codesmite
Codin - Codesmite
8,600 Points

I cant see the task that you are doing but here is an example of how you would go about doing what you have described in your question:

<?php

$first_name = "Patrick";
$last_name = "Star";

$name = substr($first_name, 0, 1) . ". " . strtoupper($last_name);

?>

First the substr() selects position 0 of the string and takes 1 character in length (the first letter). Then we concatenate ". " with the space. Finally concatenate last_name surrounded with strtoupper() function to make it upper case.

Hope this helps you with your task :)

Edit ** Found the task you are referring to and realised it was an SQL question not PHP, I'm moving your question to the development tools section of the forum.

The answer you are looking for is:

SELECT CONCAT(SUBSTRING(UPPER(first_name),1,1),". ",UPPER(last_name)) AS name FROM users;

thanks it worked!

Just some comments on this code challenge. The challenge is found here: https://teamtreehouse.com/library/database-foundations/sql-calculating-aggregating-and-other-functions/string-functions-2 and it's the third challenge of the set.

The more important matter is that the challenge never asks you explicitly to UPPER the first letter in the name. The example of A. CHALKLEY does implicitly imply that you must UPPER the first letter. I wish they'd fix the directions on the challenge to reflect this.

Robert Hemfelt
Robert Hemfelt
7,303 Points

It seemed to me like the first letter of the first name would be uppercased by default, especially since they didn't implicitly specify that we should uppercase it.