Hi I am working on some sort of a CMS page and I want to show on the /index.php page a list of all articles availble like /index.php?p=Art1.
And I have no clue on how to do that.
Any help is appreciated.
This is my index.php code:
<html>
<head>
<link rel="stylesheet" href="css/login-layout.css">
</head>
<body>
<div class="dialog-box">
<h2 style="font-size: 200%;margin-bottom: 0;">Pagini Noi</h2>
<h3 style="text-align: right; font-size:100%;margin-top: 0;">Logheazate pentru a edita paginile</h3>
<div class="pages">
<!-- Pagini \/ -->
<?php
include('config.php');
?>
</div>
</div>
</body>
</html>
Config.php contains the connection to the database $db is the variable name that i use.
The /index.php?p=Art1 method is actually a $_GET that you need to fetch. In your current example you would do:
$p = $_GET['p'];
Which if you would later echo:
echo $p;
you would get
Art1
but even before that, you should provide us with some database query example that you wish to do so we could show you how variable $p is passed on to a query that then selects the wanted rows from the table in your database. For simple mysql query you can check here: https://www.w3schools.com/php/func_mysqli_query.asp
WARNING: be sure to use mysqli_real_escape_string($p) in order to get a minimum protection from SQL injections.
Related
I have almost created a fully working dynamic page using PHP OOP. I have successfully created a working menu - that is when a menu item is clicked, relevant text is displayed on the page. However, what I want is to have the home page text displayed by default and not solely clicking the Home link.
Here is the code I am using:
<?php
include_once('includes/connection.php');
include_once('includes/Article.php');
//instanstiating the article class and ssigning it to a variable
$article = new Article;
//assigning the contents of the method called fetch_all to the variable $articles
//this fetch_all method is inside the Articles class which is assigned to the above variable $article
$articles = $article->fetch_all();
?>
<!DOCTYPE html>
<html>
<head>
<title>Simple PDO CMS</title>
<link rel="stylesheet" type="text/css" href="assets/styles.css">
</head>
<body>
<div class="container">
<table class="topMenu">
<tr>
<td>
<h1 class="siteName">site name</h1>
</td>
<!--Displaying the articles using a foreach loop-->
<?php foreach ($articles as $article){ ?>
<td class="navItem">
<?php echo $article['menuheader']; ?>
</td>
<?php } ;?>
</tr>
</table>
</div>
<p> this is where the time line will go</p>
<?php
//instanstiating the article class and ssigning it to a variable
$newArticle = new Article;
//checking if the user clicked the menu link
if (isset($_GET['id'])) {
//the display the article content
$id=$_GET['id'];
$data=$newArticle->fetch_data($id);
?>
<p><?php echo $data['bodytext']; ?></p>
<?php
} else {
}
?>
<p>This is where the footer will go</p>
</body>
</html>
So far I have tried: $id = 1; and using a redirect to index.php. Neither worked, the later due to 'to many redirects'.
I would like to keep the code I have used so far rather than redoing it again, so if you can help, please give me advice on this code.
Thanks
All you need to do is to set the id to 1 (or what ever your home page is) if there aren't any id passed in the url. No need for the if-statement.
Here's how it can be done using the null coalescing operator:
$newArticle = new Article;
// Sets the id to what $_GET['id'] is set to if it exists, otherwise, set it to 1
$id = $_GET['id'] ?? 1;
$data = $newArticle->fetch_data($id);
?>
<p><?php echo $data['bodytext'] ?? 'Page not found'; ?></p>
I also added in how you can show "Page not found" if $newArticle->fetch_data($id) didn't return anything.
I have a website with a template page that is something like this
<html>
<head>
<title>{{TITLE}}</title>
</head>
<body>
<div id = "header"> ... </div>
<?php include 'content.php'; ?>
<div id = "footer"> ... </div>
</body>
</html>
And then content.php would look something like this
<?php
$title = "xx";
#other php code here
?>
<p> more content </p>
My question is whether there is some way to set this up so that I am able to set the title from the file included in the middle of the page (without using javascript). I know that most people suggest including it at the top but if I were to do that the html would be at the top instead of between the header and the footer. I've wracked my brains for a while and I haven't really figured out a good way to do this (and there are a variety of possible files to be included; content.php is just an example, so I really do need some way to do this dynamically). I want to avoid putting too much code outside of the template. Any ideas?
Use output buffering:
<?php
ob_start();
include 'content.php';
$content = ob_get_clean();
?>
<html>
<head>
<title><?=htmlspecialchars($title)?></title>
</head>
<body>
<div id = "header"> ... </div>
<?=$content?>
<div id = "footer"> ... </div>
</body>
</html>
I'm not sure if you're using a templating engine or not (something like Laravel's Blade templates allow for this, I believe), but assuming you are using straight PHP, I have found the most efficient way to do this is to approach from the opposite direction and include the template file in each of my content files.
For example, I may have template.php, which has multiple functions, like this:
<?php
function createHeader($title, $keywords) {
//echo or <<<EOD your header with the set variables
}
function createFooter(...) { ... } //etc
And then, in my 'child' files, I would do:
<?php include('template.php'); ?>
<?php createHeader("My Website Front Page!", "fun, good times, joy"); ?>
<h1>My page content</h1>
<p>Content goes here</p>
<?php createFooter(...); ?>
This is a different structure from what you were attempting, though, and may not retain your intended structure.
I have a mysql database named "drinks", in that database I have one table named "persons" and in "persons" I have two people, Bryan(fname) Fajardo(lname) 21(age) and Andross H Age:20.
In my index.php I have links set up from all of the people in table persons.
I am trying to get my links to work so that when I click on either name, the information relevant from that person is outputted into my other page (where the link goes to) which is: insert.php.
I have been trying for hours to run some test by clicking on the Bryan link and outputting only his last name etc. etc. My objective: is to be able to link the people from "persons" table and then upon click go to insert.php and output that person's information there.
Here is my current code from Index.php.
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
//Connect to the database
$con = mysqli_connect("localhost","username","password","drinks");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
echo '<span style = "background: red ;">MSQL Connected.</span>' ;
}
$result = mysqli_query($con,"SELECT * FROM persons");
while($row = mysqli_fetch_array($result)) {
Print '<dd><a href=insert.php?
fname="'.$row['fname'].'">'.$row['fname'].'</a></dd>';
}
mysql_close();
?>
</body>
</html>
and here is my Insert .php where I want the relevant information to be printed.
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class = "full-header">
<div class = "mid-header span12 center">
</div>
</div>
<div class = "main-content-container full_w">
<div class = "span12 main-content center">
<?php
$cont = mysqli_connect("localhost","username","password","drinks");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
echo '<span style = "background: red ;">yay</span>' ;
}
$fname = $_GET['fname'];
$sel = ($cont,"SELECT * FROM persons WHERE fname ='%$fname%'");
while($rower = mysqli_fetch_array($sel)) {
Print $rower['lname'];
//why is this not printing Bryan's last name?
}
?>
</div>
</div>
</body>
</html>
Thank you in advance, I appreciate the help, I have just recently gotten into php and database building/summoning.
EDIT: I also have been reading that this is becoming deprecated and PDO is going to be used now, if you have a solution that involves PDO, I would appreciate that as well, but I am very new to PDO.
EDIT 2: Changed "table" to "persons" in insert.php query.Still did not fix.
I can understand how it is when first starting out. Once you wrap your mind around the basic parts of it the rest will flow.
Since you asked for a better way I am going to suggest a class I personally use in all my projects.
https://github.com/joshcam/PHP-MySQLi-Database-Class
Of course don't forget to download the simple MYSQLI class from the link above and include it just like I do below in your project. Otherwise none of this will work.
Here us the first page which contains the table with all the users from your persons Db table. We list them in a table with a simple edit/view button.
PAGE 1
<?php
require_once('Mysqlidb.php');
//After that, create a new instance of the class.
$db = new Mysqlidb('host', 'username', 'password', 'databaseName');
//a simple select statement to get all users in the DB table persons
$users = $db->get('persons'); //contains an Array of all users
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<table>
<th>
First Name
</th>
<th>
Last Name
</th>
<th> </th>
<?php
//loops through each user in the persons DB table
//the id in the third <td> assumes you use id as the primary field of this DB table persons
foreach ($users as $user){ ?>
<tr>
<td>
<?php echo $user['fname'];?>
</td>
<td>
<?php echo $user['lname'];?>
</td>
<td>
<a href="insert.php?id=<?php echo $user['id']; ?>"/>Edit/View</a>
</td>
</tr>
<?php } ?>
</table>
</body>
</html>
So that ends your first page. Now you need to include this code on your second page which we are assuming is called insert.php.
PAGE 2
<!--add this to your insert page-->
<?php
require_once('Mysqlidb.php');
//After that, create a new instance of the class.
$db = new Mysqlidb('host', 'username', 'password', 'databaseName');
//a simple select statement to get all the user where the GET
//variable equals their ID in the persons table
//(the GET is the ?id=xxxx in the url link clicked)
$db->where ("id", $_GET['id']);
$user = $db->getOne('persons'); //contains an Array of the user
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<table>
<th>
First Name
</th>
<th>
Last Name
</th>
<th>user ID</th>
<tr>
<td>
<?php echo $user['fname'];?>
</td>
<td>
<?php echo $user['lname'];?>
</td>
<td>
<?php echo $user['id']; ?>
</td>
</tr>
</body>
</html>
You have two main errors. On index.php you are wrapping your query string values in quotes
Print '<dd><a href=insert.php?
fname="'.$row['fname'].'">'.$row['fname'].'</a></dd>';
This should really be
Print '<dd><a href="insert.php?
fname='.$row['fname'].'">'.$row['fname'].'</a></dd>';
Next, on your second page, you need to use LIKE on your query.
$sel = ($cont,"SELECT * FROM persons WHERE fname LIKE '%$fname%'");
That said, you really should use parameters because the current method is going to open your script up to SQL Injection, and you should consider using a primary key in your querystring instead of passing the person's name.
Print '<dd><a href="insert.php?
id='.$row['id'].'">'.$row['fname'].'</a></dd>';
And your query
$id = intval($_GET['id']);
$sel = ($cont,"SELECT * FROM persons WHERE id = $id");
One final note, on your index page, you are using mysql_close instead of mysqli_close to close your database connection.
EDIT: New Question (Previous answered, stupid mistake)
I corrected the below code to call $dbh into the menu function (nav.php). However, now I am getting a new error that Google isn't helping me with (all answers are program specific):
PDOStatement::execute(): SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected in /CCU/STH Liquidations/scripts/GetData.php on line 10
No database handle errors were thrown prior to trying to pull the menu in.
I am new to PDOs, so this might be a relatively simple question - but I couldn't find an answer close enough to my problem to help.
I am building my first true content management system. I am trying to bring in a menu based on whether it is to be shown (value is either 1 or 0, to be determined by admin).
However, in just trying to read them in, I'm getting undefined variable errors between files. The files are called in the correct order, and both are pulled in by index.php.
The variable that is undefined is the $dbh in the GetData.php file.
Do you see what I'm doing wrong? Because I can't see it.
index.php:
<?php
session_start();
$title = "STH Liquidations";
$description = "Product wholesale";
$keywords = "wholesale, product, pallets";
include "parts/_head.php";
include "parts/header.php";
include "parts/nav.php";
?>
<div id="content_index">
<?php include "parts/hot_deals.php"; ?>
<div id="image_holder">
<ul class="bxslider">
<li><img src="slider/pic1.jpg" title="Welcome to STH Liquidations!"/></li>
<li><img src="slider/pic2.jpg" title="Electronics"/></li>
<li><img src="slider/pic3.jpg" title="Furniture" /></li>
<li><img src="slider/pic4.jpg" title="Appliances" /></li>
<li><img src="slider/pic5.jpg" title="Tools" /></li>
<li><img src="slider/pic6.jpg" title="Sporting Goods"/></li>
</ul>
</div>
<p class="head1">Welcome to <strong>STH Liquidations, Inc.</strong></p>
<p>We at <strong>STH Liquidations, Inc.</strong> have been in the business of buying and selling overstock and liquidated NAME BRAND merchandise from <strong>major retailers</strong>, catalog companies, and big box stores for over 10 years now. Our goal has always been to consistently provide your business with <strong>dependable</strong> and <strong>trustworthy</strong> service along with the best possible pricing that will allow you to <strong>MAXIMIZE YOUR PROFITS</strong> and <strong>minimize your risk</strong> on every deal. Whether your business is wholesale, retail, auctions, online, flea markets, or if you are a “mom and pop store”, we are able to meet your specific needs.
</p>
<p>We carry truckloads of general merchandise, furniture, housewares, tools, toys, sporting goods, jewelry lots, apparel and much more. We ship direct from the reclaim centers, which eliminates “cherry picking” and keeps <strong>YOUR COST LOW</strong>. Our simple philosophy; <strong>money saved is money made</strong>. Your success is our success.</p>
<p>Please feel free to browse our website at your leisure and CALL us with ANY questions you may have to <strong>place your order</strong>.</p>
<p>Join our FREE mailing list HERE to receive <strong>up to date listings</strong> and our <strong>HOT deals</strong>.</p>
</div>
<div id="hotdeals">
<p class="head2">Hot Deals!</p>
<div class="deals">
<p class="deal_title">K-Hardgoods</p>
<p class="deal_desc">Truckloads, general merchandise, tools, toys housewares and more</p>
<p class="deal_price">as low as $139 per pallet</p>
<p class="deal_pdf">Call for Information!</p>
</div>
<div class="deals">
<p class="deal_title">SRS Tool Truckload</p>
<p class="deal_desc">CR*STSM*N TOOLS AND MUCH MORE <br />Saws, compressors, blowers, edgers. saber saws, table saws and much more</p>
<p class="deal_price">27 PALLETS--WHLS $66,649.32 <br />SELL PRICE $12,900</p>
<p class="deal_pdf">Download PDF</p>
</div>
<div class="deals">
<p class="deal_title">W*M Power wheels</p>
<p class="deal_desc">Ride on toy truckloads
<br />150-180 units per truckload
<br />Customer returns</p>
<p class="deal_price">Price only $5,900</p>
</div>
</div>
<div class="clear"></div>
<?php
include "parts/footer.php";
?>
_head.php:
<!DOCTYPE html>
<html>
<?php
require "config.php";
require_once "scripts/GetData.php";
?>
<head>
<!-- NAME THE PAGE -->
<title><?php $title ?></title>
<!-- GET THE FAIRY DUST AND DUST BUNNIES -->
<link rel="stylesheet" type="text/css" href="scripts/basic.css" />
<script type="text/javascript" src="contact-files/contact-form.js"></script>
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<!-- bxSlider -->
<script src="scripts/jquery.bxslider.min.js"></script>
<link href="scripts/jquery.bxslider.css" rel="stylesheet" />
<script src="scripts/muscles.js"></script>
<!-- TELL GOOGLE WHAT IT WANTS TO HEAR -->
<meta name="description" content="<?php $description ?>">
<meta name="keywords" content="<?php $keywords ?>">
<!-- FIX ENCODING ERROR -->
<meta charset="UTF-8">
</head>
<!-- =============== -->
<!-- HEADER -->
<!-- =============== -->
config.php:
<?php
$host = "localhost";
$user = "root";
$pass = "root";
$database_name = "sthliquidations";
// Create connection
try
{
// PDO Connection
$dbh = new PDO("mysql:host = $host; dbname = $database_name", $user, $pass);
}
catch (PDOException $e)
{
echo $e -> getMessage();
}
// Show me any exceptions
// TURN THIS OFF WHEN LIVE
$dbh -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
?>
GetData.php (and where the error is being thrown):
<?php
function menu ($dbh)
{
// Make a call to the database
$menu_handle = $dbh->prepare("
SELECT * FROM cats
WHERE menu = ?;
");
$menu_handle->execute(array(1));
// Testing
$row = $menu_handle->fetch();
echo "<pre>";
echo $row;
echo "</pre>";
}
?>
nav.php (what's making the call in the first place):
<!-- NAVBAR -->
<div id = "sidenav">
<div id = "leftnav">
<ul class = "menulink">
<li>Home</li>
<li>About Us</li>
<?php menu($dbh); ?>
<li>Freight Services</li>
<li>Contact Us</li>
<li>Glossary</li>
</ul>
</div>
</div>
It was a simple fix after all. Scope was correct, call was correct - simply forgot the parameter.
Once I added the $dbh call in the correct places, I started getting this error:
PDOStatement::execute(): SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected in /CCU/STH Liquidations/scripts/GetData.php on line 10
After some trial and error, I figured out that the PDO database connection script doesn't like spaces.
Connected perfectly after that fix and have gotten my menu working properly, even able to pull in only those menu links set to true.
Days work done LOL!
I hope the title I used here was understandable...
I have a database with two columns: ward_id and ward_name.
I wish to create dynamic pages for each ward and have the ward_name show in the page title. I have created a header.php file which I am including.
I am passing the id through the URL using ....?wid={$row['ward_id']} which is working fine when I create other queries that use that id to get data from the database.
However the problem I am having is that the page refuses to display the ward_name as the page title. I expected something like this to work:
$wardid = $_GET['wid'];
$query = "SELECT ward_name, ward_id FROM wards WHERE ward_id=$wardid";
$result = mysql_query($query);
while ($row=mysql_fetch_array($result))
{
$pagetitle = "$row['ward_name']";
}
But it doesn't, I have tried so many variations on the above I can't possibly remember them all now so I really hope someone can help me... Here is the code as it currently stands:
Header Page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<title><?php echo $pagetitle; ?></title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wholepage">
<div class="headlinewrapper">
<div class="headline">
<h1></h1>
<h2></h2>
</div>
</div>
<div class="headlinesidewrapper">
<div class="headlineside">
<p>shv jsfj sjnsf jnsf nsnf nj njsfn
njfjn sfns njf njnsf njs dgbjn dn jnd njjn dd d d nj njd njnd njd nn djndj njd</p>
</div>
</div>
<div class="topnavigation">
<ul>
<li>Home</li>
<li>Boroughs</li>
<li>Wards</li>
</ul>
</div>
<div class="sidebar">
</div>
<div class="mainpagewrapper">
Dynamic page:
<?php
$pagetitle = "Hello";
include ('header.php');
?>
<div class="mainpage">
<div class="infobox">
</div>
<?php
require('mysqli_connect.php');
mysql_select_db('onetwom2_london');
$wardid = $_GET['wid'];
$query = "SELECT ward_name, ward_id FROM wards WHERE ward_id=$wardid";
$result = mysql_query($query);
while ($row=mysql_fetch_array($result))
{
echo "<div class=\"boroughlist\"><p>{$row['ward_name']}</p></div>" ;
}
$pagetitle = $result;
?>
<div class="clear">
</div>
</div>
</div>
</div>
</body>
</html>
So I just want to know how/if it is possible to match the id passed through the URL to the ward_id stored on the database and then have the page title display the ward_name linked to that id. I apologise if this is a really easy question, I have spent hours trying to work this out and I am completely stumped! (the code I posted above is just the end result of 5 hours of frustration so please appreciate I have tried hard before asking you for help :) )
You should step through the problem to see where it goes awry, var-dump $pagetitle in the while loop. See what is being stored if it comes out as NULL you are not retrieving anything from the DB and there is an issue with either Query. if it has the correct variable the problem is with your PHP. Var_dump $pagetitle in your header.php file to be sure it is getting the correct variable.
Let me know the outcome and I can help you from there
<?php
$wardid = $_GET['wid'];
$query = "SELECT ward_name, ward_id FROM wards WHERE ward_id=$wardid";
$result = mysql_query($query);
while ($row=mysql_fetch_array($result))
{
$pagetitle = "$row['ward_name']";
//Step Through The Problem
var_dump($pagetitle);
}
include ('header.php');
?>
<div class="mainpage">
<div class="infobox">
</div>
<?php
require('mysqli_connect.php');
mysql_select_db('onetwom2_london');
$wardid = $_GET['wid'];
$query = "SELECT ward_name, ward_id FROM wards WHERE ward_id=$wardid";
$result = mysql_query($query);
while ($row=mysql_fetch_array($result))
{
echo "<div class=\"boroughlist\"><p>{$row['ward_name']}</p></div>" ;
}
$pagetitle = $result;
?>
<div class="clear">
</div>
</div>
UPDATED - Try This
<?php
require('mysqli_connect.php');
mysql_select_db('onetwom2_london');
$wardid = $_GET['wid'];
$query = "SELECT ward_name, ward_id FROM wards WHERE ward_id=$wardid";
$result = mysql_query($query);
while ($row=mysql_fetch_array($result))
{
$pagetitle = $row['ward_name'];
//Step Through The Problem
var_dump($pagetitle);
}
include ('header.php');
?>
<div class="mainpage">
<div class="infobox">
</div>
<?php
$result2 = mysql_query($query);
while ($row2=mysql_fetch_array($result2))
{
echo "<div class=\"boroughlist\"><p>{$row2['ward_name']}</p></div>" ;
}
?>
<div class="clear">
</div>
</div>
Do yourself a favor and use some ORM or library that gives you parameterized queries.
This code opens you right up for SQL-injection attacks:
$wardid = $_GET['wid'];
$query = "SELECT ward_name, ward_id FROM wards WHERE ward_id=$wardid";
First of all, avoid using double quotes as much as possible. Use single ' quotes instead. Double quotes makes php look for variables in the string which will be parsed. Using single quotes, any variables in the string will be echo'd as plain text, increasing overall performance.
So,
instead of
$pagetitle = "$row['ward_name']";
you want to use
$pagetitle = $row['ward_name'];
The same here:
echo "<div class=\"boroughlist\"><p>{$row['ward_name']}</p></div>";
should be changed into:
echo '<div class="boroughlist"><p>'.$row['ward_name'].'</p></div>';
Using single quotes makes \" also obsolete, making the code more readable and it'll be easier to write.
For working with databases in PHP I recommend you to work with a MySQLi Class. Have a look at https://github.com/ajillion/PHP-MySQLi-Database-Class . It's easy to implement and the learning curve is low.
MySQLi is the successor of MySQL (which is deprecated by now). With MySQLi prepared statements got introduced which make your queries containing (user) input save against SQL Injection. PDO would be even better, but it's harder to use.
Regarding $wardid = $_GET['wid'];: Make sure the value is being interpreted as integer. So try this:
$wardid = (int) $_GET['wid']; // type cast to integer aka Type Juggling
$query = 'SELECT ward_name, ward_id FROM wards WHERE ward_id=`'.$wardid.'` LIMIT 1';
Notice the LIMIT 1. This limits the query to one result, making it perform better as it stops right after it has found a result.
Good luck on your way learning more about SQL and PHP :-)
Edit:
According to a comment from the questioner, I want to add a rewritten example of the code given in the question:
<?php
// I'll demonstrate how to use the MySQLi Class
require_once('mysqlidb.php');
// Connect to the database
$db = new Mysqlidb('host', 'username', 'password', 'databaseName');
// Get the wid from the uri
$wardid = $_GET['wid'];
// Fetch the page title from the db
$result = $db->where('ward_id', $wardid)->get('wards', 1);
$pagetitle = $result['ward_name'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><?php echo $pageTitle; ?></title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- A templating engine like smarty would make things easier -->
<section class="whole-page">
<div class="headline-wrapper">
<div class="headline">
<h1></h1>
<h2></h2>
</div>
</div>
</section>
<div class="headline-sidewrapper">
<div class="headline-side">
<p>Lorem ipsum...</p>
</div>
</div>
<nav class="top-navigation">
<ul>
<li>Home</li>
<li>Boroughs</li>
<li>Wards</li>
</ul>
</nav>
<aside class="sidebar"></aside>
<section class="mainpage-wrapper">
<!-- Dynamic page part - I recommend using a separate template that will be included here -->
</section>
</body>
</html>
This is a basic example using the MySQLi Database Class. I recommend you to use a template engine like smarty to make jobs like this easier. Also consider reading 'Separation of concerns'.