Online Photo Album Development using PHP and GD: Part 2 - Code: Explained
(Page 2 of 5 )
The HTML code is straight-forward; however, I'll explain the PHP code from above:
include("../include/config.php");
?>
We'll be including config.php in all of our files. The config.php file allows us to make use of global variables throughout our application. Our config.php file looks like this:
<p><!--p<-->// Include file for database connectivity
<br />$db_server = "localhost";
<br />$db_user = "admin";
<br />$db_pass = "admin";
<br />$db_name = "album";
<br />// Number of images to display per row in gallery view
<br />DEFINE("IMAGE_DISPLAY", 3);
<br />/*****
<br />* Connects to database system
<br />*/
<br />function db_connect(){
<br />global $db_server;
<br />global $db_user;
<br />global $db_pass;
<br />global $db_name;
<br />$dbcnx = mysql_connect($db_server, $db_user, $db_pass) or die("Error connecting
to database: " . mysql_error());
<br />$dbsel = mysql_select_db($db_name, $dbcnx) or die("Error reading from database
table: " . mysql_error());
<br />}
<br />/*****
<br />* Displays HTML output page. The message argument, if passed,
<br />* will be displayed to the user. The title element, is passed,
<br />* replaces the page title, and the cell Boolean places the page
<br />* $msg between
<td />
</td />
<br />*/
<br />function displayPage($msg = "", $title="", $cell = true){
<br />
<br />
<br />
<br />
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<br />
<tbody>
<tr>
<br />
<td>
<br />
<table cellspacing="0" cellpadding="3" width="60%" align="center" border="0">
<br />
<tbody>
<tr>
<br />
<td valign="top" width="40%">
<h1><!--p echo($title);--></h1></td>
<br /></tr>
<br /></tbody></table>
<br />
<table cellspacing="0" cellpadding="5" width="60%" align="center" border="0">
<br />
<tbody>
<tr>
<br /><!--p<-->// Display opening
<td>tag
<br />if ($cell)
<br />echo(" </td>
<td>");
<br />echo($msg);
<br />
<br />// Display closing </td>
<td>tag
<br />if ($cell)
<br />echo("</td>");
<br />
<br /></tr>
<br /></tbody></table>
<br /></td>
<br /></tr>
<br /></tbody></table>
<br />
<br /><!--p<-->}
<br /></p>
>
Next: Configurating >>
More MySQL Articles
More By Frank Manno