Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
We have our catalog and category pages with thumbnails of the items. We are going to add one more page to display the details for each item. We will grab the details of the specific item we choose. If we can't find the item specified, we redirect to the Catalog page.
-
0:00
Our library is really coming together,
-
0:02
we have all our data loaded and sorting on our catalog and category pages.
-
0:06
Currently all we see are the thumbnails of the items,
-
0:08
but we have a lot more data that we know about each item.
-
0:12
The last thing we need to do is to be able to display the details of each item,
-
0:17
let's add one more page.
-
0:19
Create a new page named details.php.
-
0:24
We want to make sure that this is right next to our other pages in the root of
-
0:28
our site.
-
0:30
Copy the entire top code block from php all they way down to including the header.
-
0:41
And paste it into our details page.
-
0:43
Now we'll make the changes specific to this page.
-
0:46
To pull the details for
-
0:47
a specific item, we're going to utilize the get variable again, to pass the ID.
-
0:52
Let's change the get variable in the first if statement.
-
0:56
Where it's looking to see if it is set get cat.
-
0:59
We're gonna change cat to id.
-
1:03
We're going to change what we're doing with the variable, so
-
1:05
let's remove this entire nested if statement.
-
1:09
If an ID was passed, we want to check if that ID is in our catalog.
-
1:13
So let's create a new ID variable.
-
1:18
We'll assign it the value of GET id.
-
1:26
Then we want to add another if is set to check for that ID within our catalog.
-
1:30
If isset catalog.
-
1:38
ID.
-
1:41
If we find an item, let's hit the value of that item to an item variable.
-
1:50
If we don't find an item or we aren't passing a variable,
-
1:56
then our item variable will not be set.
-
2:00
And we want to redirect them to a full catalog.
-
2:03
So down here we'll do another if isset item.
-
2:11
But we're going to change and use our negation operator.
-
2:17
So, if not isset item we're going to redirect.
-
2:22
The command for this is header.
-
2:25
This has nothing to do with our own header file that displays the logo and menu.
-
2:29
This is part of the HTTP, the hyper text transfer protocol that defines how
-
2:34
the server and the browser communicate before any HTML gets passed.
-
2:38
The header field we want to define is location.
-
2:45
This tells the browser to look for a different page, catalog.php.
-
2:52
We need to make sure we don't send anything else to the browser before
-
2:55
this redirect.
-
2:56
Even a blank line at the beginning of the file will cause the redirect to fail.
-
3:00
This is because a blank line, or a echo statement, will cause a header response
-
3:04
to be sent back to the requesting computer, nullifying the redirect header.
-
3:09
We also want to add an exit command.
-
3:13
This makes sure nothing else is processed while the redirect is happening.
-
3:17
The last thing we want to do in this top section of our file,
-
3:21
is to move the page title in the section below our redirect.
-
3:28
Then we know we can use the item values.
-
3:30
We'll change page title to item title.
-
3:38
We can leave section null since we're not using it in our navigation.
-
3:41
Now let's start adding the content for this page.
-
3:46
Start adding our divs.
-
3:48
Div class="section page".
-
3:57
Div class="wrapper".
-
4:07
Within the wrapper the first that we want to add is our image.
-
4:10
We're going to write the HTML for the image first.
-
4:12
Then add the PHP we need.
-
4:13
Image source and alt.
-
4:22
Now we'll fill in the PHP needed to grab the details of the item, php echo
-
4:27
$item["img"].
-
4:38
Php echo item title.
-
4:46
Included in the CSS you've been given is a style for this image.
-
4:49
We need to surround it with the div tag with a class of media picture.
-
4:59
Media-picture.
-
5:07
We also want to include a span tag, to give it a nice border.
-
5:17
When we take a look at this page in the browser, let's pull up this browser
-
5:23
page details.phpid=101.
-
5:29
We see a nice image but what we really want are the details.
-
5:32
Now let's go back and add those.
You need to sign up for Treehouse in order to download course files.
Sign up