Learn about...
Connection details have been emailed to you.
In lab, I will demonstrate how to use WinSCP to connect to our remote server.
Here are the server details:
ftp.sienasellbacks.com
or ftp.breimer.net
yourID@sienasellbacks.com
or yourID@breimer.net
Task: Open the email with your FTP connection settings to see which server you connect to
Our two remote webservers (sienasellbacks.com and breimer.net) each have a databased for storing website content called sienasel_pages
and breimern_pages
Currently, the database has a table called pages
with the following fields and content:
In the tasks below, you will create the following script: part1.php which fetches content from a database to create a basic web page.
Task:
Click on the part1.php link and add a URL parameter indicating the
pageid of a country, i.e., part1.php?pagid=usa
. Look at the table above to see
the pageids. Try a different pageid. Try a pageid that is not likely to exist.
The script above connects to the database (sienasel_page or breimern_pages) and uses the pageid passed in the URL to fetch both the title and content. The content is simply a long text string encoded with HTML.
part1.php
and save it in your lab6
folderpart1.php
, get the pageid from the URL:$pageid = $_GET['pageid'];
$pageid
is null, set it equal to 'home'
lab6
folder to your remote serverusername.siencs.com/lab6
or
username.breimer.net/lab6
to test your script.part1.php?pageid=usa
part1.php?pageid=
part1.php?
part1.php
part1.php
, add the following code below your if statementecho_head('Countries of the World'); echo_content($pageid); echo_foot();
echo_head($title)
function at the very top of part1.php
to create a minimum HTML document from the <!doctype html>
tag to the opening body
tag.
Instead of hardcoding the title, slice in the $title variable passed into the function.
This function should echo HTML code, so use single quotes.echo_foot()
function to echo the closing body
and html
tags.
echo_content($pageid)
to echo the following:
'<div class="container"> <h1>Title for'.$pageid.'</h1> <main>Main content will go here</main> <p> <a class="btn btn-primary" href="?pageid=parent">Back to parent</a> </p> </div>'
username.siencs.com/lab6
or
username.breimer.net/lab6
to test your script.pageid
is properly outputted in the titleecho_content($pageid)
, add the following code before your echo statement$result = run_query("SELECT title, content, parent FROM pages WHERE pageid = '".$pageid."'"); $content = $result->fetch_assoc();
$pageid
into the query.fetch_assoc()
is a method on the query "object" that return one row of data
as an associative array.run_query($sql)
function.mysqli
constructor
and connect to "localhost" with the following connection settings:
sienasel_p_user
or breimern_p_user
depending on what server you are on.sienasel_pages
or breimern_pages
depending on what server you are on.$mysqli
,
you can execute the query string ($sql
) using the following code:$result = $mysqli->query($sql);
$result
$result
is not the actual data returned by the query,
but rather an object that will allow us to fetch the query result row by row
using either the method fetch_row
, which return a regular array, or
fetch_assoc
, which returns an associative array where
the array indices are the field names.run_query($sql)
function,
modify the echo_contents($pageid)
function so
that the title, content and parent are properly sliced into the echo statement.$content
should be an associative array where
$content['title']
is the title of the page,
$content['content']
is the content of the page and
$content['parent']
is the parentid ot the pageusername.siencs.com/lab6
or
username.breimer.net/lab6
to test your script.part1.php?pageid=usa
to
see if the content properly loads and to see if the back link goes
to North America. Try other pageids to be sure your scripts are working.In this next part, we will generate a navigation menu to all the pages in the database.
part1.php
as part2.php
part2.php
, add a function call to echo the navigation menu as follows:echo_head('Countries of the World'); echo_nav('Countries', $pageid); echo_content($pageid); echo_foot();
echo_nav($short_title, $pageid)
function as follows:echo_nav_start($short_title)
function as follows:echo_nav_end()
function as follows:echo_nav_item($pageid, $title, $current_page)
function as follows:part2.php
to make sure the navigation menu works.
In this next part, we will make some modification so the active page is highlighted
part2.php
, modify the echo_head
function
to include the following stylesheet: <link rel="stylesheet" href="style.css">
style.css
and add CSS to give
.active
element bold text and different colorstyle.css
to your lab6
folder on the server.part2.php
to make sure the active hyperlinks are changed.
In this next part, I simply wish to demonstrate how we can add external stylesheets and additional structures with classes to transform the website to have mobile-first menu.
part3.php
part3.php
to see how the menu is rendered.
You only need to upload part2.php
and submit the file in Blackboard.
If applicable, in the comment area of Blackboard put your partner's name.
The deliverable must be submitted in Blackboard by midnight on the day before your next scheduled lab meeting. If you wish to work alone, you can submit the deliverable yourself. However, you are encouraged to work with your partner and you can submit together. When submitting as a lab pair, be sure to include your partner's name in the comment area when you submit via Blackboard.
Outside of lab, you are only permitted to work with your lab partner. Do not share your work with any other student.