Working with PHP if Statements

June 4, 2009

PHP if statments is some of the first a beginner learns about, there is a useful PHP Tutorial at Brugbart.

Today i’m going to make a php if then else statement, to chose different CSS settings, based on choices the user makes. PHP is supported on most shared hosts, so its a good choice when developing your website.

To create a stylesheet selector, we can use the below code, provided by Brugbart.

<style type=”text/css”>
<?php session_start();

if ((isset($_GET['StyleSheet'])) && (preg_match(“/^[\d]{1,2}$/D”, $_GET['StyleSheet']))) {

$_SESSION['styl'] = $_GET['StyleSheet']; } else { // Default StyleSheet
$_SESSION['styl'] = ’1′; }
echo ‘@import url(“StyleSheet’ . $_SESSION['styl'] . ‘.css”);’;
?>
</style>

This allow me to select another style, simply by clicking a static HTML link. See below.
<a href=”?StyleSheet=1″>StyleSheet 1</a>

This technique can also be used to change single styles, such as the font-size as we are using the selector in the head section of out page.

<style type=”text/css”>
<?php session_start();

if ((isset($_GET['StyleSheet'])) && (preg_match(“/^[\d]{1,2}$/D”, $_GET['StyleSheet']))) {

$_SESSION['styl'] = $_GET['StyleSheet']; } else { // Default StyleSheet
$_SESSION['styl'] = ’1′;

if ($_SESSION['styl'] == ’1′) { echo ‘p { font-size: 2em; }’; }
elseif ($_SESSION['styl'] == ’1′) { echo ‘p { font-size: 4em; }’; }
else { echo ‘p { font-size: 4em; }’; }

}
?>
</style>

How to create a website

January 31, 2009

Websites are made with HTML and CSS. HTML is a markup language used to markup the text in your documents, while css is being used to change the font size, background, width and height of your page.

There are editors to help people create a website, these are often known as WYSIWYG (What You See Is What You Get) editors, those editors do still require that you have at least basic understanding of HTML, unless you want to end up with invalid code.

You can even create a website in a text editor like notepad, so you don’t really need to buy one of the expensive editors, some of the best tools you can use are even free.

Links to HTML Tutorials:
An Introduction to HTML
Paragraphs and Headings in HTML
Images and Links in HTML
Tables in HTML
Using SPAN and DIV for Layout in HTML
Ordered and Unordered lists in HTML
CSS Float Based Layouts
PHP is a server-sided scripting language, used to create dynamic sites, it is usually used with MySQL which is a free database solution. There are some useful PHP Tutorials below.
PHP Sessions
if then else in php
While and For Loops in PHP


Follow

Get every new post delivered to your Inbox.