Gallery-Mysql site,
PHP-MYSQL Course |
In the steps of this tutorial, I will be using the XAMPP
server for Windows ... |
May
2015
| |
General
Info: |
|
Connection Name
="$result" Server Name = "localhost" User
Name = "root" Password = "" Database Name =
"gallery" |
|
Database Name =
"gallery" 1-Table Name = "category"
2-Table Name = "items" |
| |
| |
1- The Code of db_functions.php - (or
function db_connect) |
If you wish to install a local testing server, you can download the
XAMPP package for Windows http://www.apachefriends.org/en/xampp.html
Once
XAMPP is a completely installed. XAMPP is an easy to install Apache
distribution containing MySQL, PHP and Perl. You can use the
XAMPP Control Panel to start your testing server.
- Click Start next to both Apache and MySQL to start the services.
Starting these services can take a few seconds. When it is complete,
'Running' will display beside each option.
To make your testing server start automatically
when your computer starts, you can check the Svc checkbox beside both
options. If the XAMPP Control Panel is not already running, go to
C:\xampp\control.exe to open the panel. |
1- XAMPP Control Panel
|
|
|
With your testing server now installed and running, there are a few
final steps you should take to make sure everything is configured to work
perfectly.
- Open a web browser such as Firefox or Internet Explorer.
- In the Address bar, enter http://localhost.
You should see a
XAMPP splash screen with language options.
- Choose your preferred language.
You should now see a confirmation
window informing you that 'You have successfully installed XAMPP on your
system' |
2-
List of Files
the php
+ sql files and Folders corresponding, stored at \30-Course,
Gallery-Mysql site, PHP-MYSQL\Gallery-Mysql Folder the main php
file- index.php |
|
|
Defining a Dreamweaver
Site |
Once a testing server is set up, either locally or using
a remote hosting service, you will need to define a site for Dynamic
Development in Dreamweaver |
|
In Dreamweaver go to Site -> New Site.
Note:
you can edit an existing site definition by going to Site -> Manage
Sites. Select the site you wish to modify, then click the edit
button. |
|
Step 2: Enter the local
Information
In the
first section of the site definition, you will set the Local Information.
This sets the Site Name, and local path for files in your
site.
When using XAMPP in a windows system, it may be that the site
root is mapped to: C:\xampp\htdocs so the new site folder would be created under
that location: C:\xampp\htdocs\Gallery-Mysql-site
In this screen shot, using DW CS6 on a Windows system with XAMPP
installed. you will set the Local Information. This sets the Site Name,
and local path for files in your site. Site
Name:
Gallery-Mysql-site local Site Folder: C:\xampp\htdocs\Gallery-Mysql-site |
|
|
The next setting is to connect to servers. In DW CS6 and above, this
done by selecting the servers section: |
|
|
and clicking the plus icon to define a new server
connection. at Basic tab, For the Name you can enter the same
name as the Site definition, When using a local testing server, set
Connect Using to "Local/Network" |
|
Set the Server Folder to the same location as the local
files set in the initial Site Settings. Server
Name:
Gallery-Mysql-site connect
using:
Local/Network Server
Folder:
C:\xampp\htdocs\Gallery-Mysql-site Web
URL:
http://localhost/Gallery-Mysql-site |
|
|
at Advanced tab, |
Click the advanced button and set the Application model
to PHP / MySQL Server Model: PHP MySQL |
|
then click Save. Once the connection is
defined, there are check boxes to set the connection as a testing or
remote connection, check the testing option. |
|
and then Click Save, the Dreamweaver dialog box
display: |
|
Step 4:
Manage Sites |
you can edit an existing site definition by going to Site
-> Manage Sites. Your Sites: Gallery-Mysql-site |
|
then click Done |
Setup the site's Testing Server and then click
OK |
|
|
|
n this section, we'll look into how to create a database.
A database is used to store information for your site. Copy
gallery.sql file from
...\\\30-Course, Gallery-Mysql site, PHP-MYSQL\Gallery-Mysql Folder
to folder C:\xampp\htdocs\Gallery-Mysql-site |
Most web hosts use a control panel for managing your
site, in the control panel they will have a way to create a MySQL
Database. Once a database has been created, you can use phpMyAdmin to edit
it. |
phpMyAdmin is also available using most Local Testing
server packages like XAMPP. The Start pages for those server will have a
link to open phpMyAdmin.
In phpMyAdmin, go to the Import tab. Use
this .sql script (C:\xampp\htdocs\Gallery-Mysql-site\gallery.sql)
to create the gallery database that we will be using
:.
Step
1: import SQL file On the import tab, Click the chose
file button, and select the gallery.sql file that you
downloaded, and click the Go
button to have the database created: |
|
|
System Send/Display Message about
gallery.sql: Import has been succcessully
... |
|
the Database "gallery" stores 2 tables:
category and items On the Structure tab, to be
Displays: the Table "category" of Database
"gallery" |
|
|
|
index.php page
File |
Now that a site and a database are created, lets connect
the 2 together.
Before creating the database connection, a new PHP
file needs to be created and saved to the site |
Go to File -> New. In the File Creation dialog, select Blank Page.
From the page type section, select PHP and click the
create. |
|
|
Go to File -> Save. In the Save As option, enter
"index-pagination-simple-1.php"
In the Where section, select the
folder for your site. |
|
|
Step 3: the Site has been
defined - testing server - Once the site has been
defined, at Dreamweaver - Dw display current Message: "This page
may have dynamically-related files that can only be discovered by the
server. Discover | Preferences. |
|
|
Step 4: the software
connection, php file |
connection
name: $result MySQL
server:
localhost User
name:
root Password:
Database: gallery |
1- The
Code of db_functions.php - (or function
db_connect) |
<?php
function
db_connect() { // change to mysql_pconnect('yourhost',
'yourusername', 'yourpassword')or mysql_connect(...) $result =
mysql_pconnect('localhost', 'root', ''); if(!$result) return
false; if(!mysql_select_db('gallery')) // or whatever you called
your database return false;
return
$result; } | |
|
Step 5:
The Designs and Codes of index.php
the main file -
index.php includes the php file: db_functions.php |
1- The Design of
index.php |
|
|
2- The
Code of index.php |
<!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
http-equiv="Content-Type" content="text/html; charset=utf-8"
/> <title>Pictures Gallery</title> <meta
name="keywords" content="Pictures gallery ..."> <style
type="text/css"> .header { position:absolute; height:
115px; width: 800px; left: 5px; top: 5px; border: 1px
solid
#E1F9FB; } .leftside { position:absolute; width:
175px; left: 5px; top: 120px; border: 1px solid
#E1F9FB; } .center { padding:
20px; position:absolute; height: 425px; width:
625px; left: 180px; top: 120px; border: 1px solid
#E1F9FB; } .footer {
position:absolute; z-index:
0; height: 75px; width: 800px; left: 5px; top:
820px; padding: 15px; } a:hover { background-color:
#DBE4FD; } a:active { color: #33A6B3; } a:link { color:
#06820D; } a:visited { color: #858585;
} </style> </head>
<body> <table
width="80%" border="0" align="center" cellpadding="4"
cellspacing="3"> <tr> <td><table
width="100%" border="0" cellspacing="0"
cellpadding="4"style="background-color: #DADADA;"
> <tr> <th scope="col" align="center"
width="30%"><img src="images/log.png" width="230" height="80"
longdesc="images/log.png" /></th> <th scope="col"
align="center" width="70%"><table width="100%" border="0"
cellspacing="4" cellpadding="4"> <tr> <th
scope="col" align="center"><font color="#8080FF"
size="+3"><b>Pictures
Gallery</b></font><br></th> </tr> <tr> <td
align="center" height="30px" valign="bottom">Dowloand the source
code or pictures free? Click <a
href="pgallery.rar">here</a></td> </tr> </table></th> </tr> </table></td> </tr> <tr> <td
><table width="100%" border="0" cellspacing="0"
cellpadding="0"> <tr> <th scope="col"
align="center" width="70%"> </th> <th
scope="col" align="center" width="30%"> <?php
//
output the date and time echo date("M-d-Y - G.i:s<br>",
time());
?> </th> </tr> </table></td> </tr> <tr> <td><table
width="100%" border="0" align="center" cellpadding="0"
cellspacing="0"> <tr> <th scope="col" align="left"
width="30%" valign="top" style="background-color:
#DADADA;"><table width="94%" border="0" align="center"
cellpadding="0" cellspacing="0"> <tr> <th
scope="col"> </th> </tr> <tr> <td
align="left"> <?php
require_once('db_functions.php'); // // BEGIN LEFT
SIDE MENU CREATION // db_connect(); // Optional parameter
($database = 'database_name') default = 'gallery' //SELECT
`cat_id`, `cat_title` FROM `category` WHERE 1 $sql_text = "SELECT
* FROM category ORDER BY cat_title ASC"; $query =
mysql_query($sql_text);
echo "<div >"; echo
"<a href='index.php?cat_id_fk=0'><h2>View All
Categories</h2></a>\n"; echo "Or click on one of
these categories:<hr>\n"; echo
"<table>\n"; while($result =
mysql_fetch_array($query)) { $cat_id =
$result['cat_id']; $cat_title =
$result['cat_title']; if($cat_id != 0) // Don't want to display
the "All" category since there's already a link for it
above { echo '<tr>';
echo "<td><a
href='index.php?cat_id_fk=$cat_id&cat_title=$cat_title'>"
; echo $cat_title; echo
"</td></a></tr>\n"; } } echo
"</table>\n"; echo "</div>\n"; // // END LEFT
SIDE MENU CREATION //
?>
</td> </tr> <tr> <td
align="left"> </td> </tr> <tr> <td
align="center"></td> </tr>
</table></th> <th
scope="col" align="center" width="70%" valign="top"> <table
width="100%" border="0" cellspacing="0"
cellpadding="0"> <tr> <th scope="col"
align="center"> <?php $page = (int)
(!isset($_GET["page"]) ? 0 : $_GET["page"]);
// Which gallery
are we in? //SELECT `item_id`, `cat_id_fk`, `item_num`, `title`,
`remarks`, `price`, `qty_on_hand`, `box`, `mark`, `year`, `tags`
FROM `items` WHERE 1
if
(!isset($HTTP_GET_VARS['cat_id_fk']))
{ $sql_text =
"SELECT * FROM items ORDER by item_num
ASC"; } else { $cat_id_fk =
$HTTP_GET_VARS['cat_id_fk']; $sql_text = "SELECT * from items
WHERE cat_id_fk = '$cat_id_fk' ORDER BY item_num ASC";
} $query = mysql_query($sql_text);
// Sets page
number, if no page is specified, it will create page
1
if(!$page) { $page = 1; } $prev_page = $page -
1; $next_page = $page + 1;
// Set the number of rows and
columns you want per page and the number of pictures
per_page $rows = 3; // change to # of rows you want per
page $columns = 3; // change to # of columns you want per
page $per_page = $rows * $columns;
// Sets up specified
page $page_start = ($per_page * $page) - $per_page;
$num_rows = @mysql_num_rows($query); if($num_rows <=
$per_page){ $num_pages = 1; } else if (($num_rows %
$per_page) == 0){ $num_pages = ($num_rows / $per_page); }
else { $num_pages = ($num_rows / $per_page) + 1; }
$num_pages = (int) $num_pages; if (($page > $num_pages)
|| ($page < 0)){ error("You have specified an invalid page
number"); } $sql_text = $sql_text . " LIMIT $page_start,
$per_page"; $query = mysql_query($sql_text);
?> </th> </tr>
<tr> <th
scope="col" align="center"><table width="100%" border="0"
align="center" cellpadding="0"
cellspacing="0"> <tr> <th scope="col"
align="center" valign="top"> <?php // //
***BEGIN SECTION TO CREATE ROWS AND COLUMNS*** //SELECT
`item_id`, `cat_id_fk`, `item_num`, `title`, `remarks`, `price`,
`qty_on_hand`, `box`, `mark`, `year`, `tags` FROM `items` WHERE
1 // echo "<tr>\n"; $current_column = 1; while
($result = mysql_fetch_array($query)) { $item_id =
$result["item_id"]; $cat_id_fk =
$result["cat_id_fk"]; $item_num = $result["item_num"]; $title
= $result["title"]; $remarks = $result["remarks"]; $box =
$result["box"]; if($current_column <= $columns) { echo
"<td class='current'><center>\n";
echo
"<br><a href='details.php?item_id=$item_id'>\n"; echo
"<img src='thumbs/".$item_num.".jpg'
title='".$item_num."'>\n"; echo '</a>'; echo
"<br><font color='blue'><b>#item:
$item_num</b></font>"; echo "<br><a
href='details.php?item_id=$item_id'>".$title."</a>"; echo
"</center></td>\n";
$current_column++;
}
if($current_column >
$columns) { echo "</tr>\n"; echo
"<tr>\n"; $current_column = 1; } } // // ***END
SECTION TO CREATE ROWS AND COLUMNS*** //
$PHP_SELF =
&$_SERVER['PHP_SELF'];
// // ***BEGIN PAGE LINKS
SECTION*** //
if ($prev_page) echo "<a
href=\"$PHP_SELF?page=$prev_page\">< Prev</a>";
//
This loops the Pages and displays individual links corresponding
// to the photos. for ($i = 1; $i <= $num_pages; $i++)
{ if ($i != $page) echo " <a
href=$PHP_SELF?page=$i>$i</a>"; else echo
" Page $i\n"; }
// This displays the
"Next" link. if ($page != $num_pages) echo " <a
href=\"$PHP_SELF?page=$next_page\"> Next ></a>"; // //
***END PAGE LINKS
SECTION*** // ?> </th> </tr> </table></th> </tr>
<tr> <th scope="col" align="center"><br
> There are <?php echo $num_rows; ?> items in the
<font color='blue'></font> gallery. For any Detail,
Click
item.
</th> </tr>
</table>
</th> </tr> </table></td> </tr> <tr> <td
height="10px"> </td> </tr> <tr> <td
align="center" height="10px" style="background-color: #DADADA;
font-family: 'Times New Roman', Times, serif; font-size:
12px;"><a href="www.puresoftwarecode.com">@ pure software
code</a></td> </tr> </table> </body> </html> | |
|
3- the Code of
db_functions.php |
<?php
function
db_connect() { // change to mysql_pconnect('yourhost',
'yourusername', 'yourpassword')or mysql_connect(...) $result =
mysql_pconnect('localhost', 'root', ''); if(!$result) return
false; if(!mysql_select_db('gallery')) // or whatever you called
your database return false;
return
$result; } | |
|
4- the Design and Code of
details.php the file - details.php
includes the php file: db_functions.php |
1- The Design of
details.php |
|
|
2- The Code of
details.php |
<html> <head> <title><?php
echo "Precious Moments: $title" ?> </title> <meta
name="keywords" content="<?php echo "$title, $item_num, Precious
Moments, Figurine"; ?>">
<base
href="http://localhost/Gallery-Mysql-site/">
</head> <body> <center> <table
width="600" border="1"> <tr> <td width="85"
bgcolor="#DBE4FD"> <center><img src="thumbs/<?php
echo $item_num;
?>.jpg"></center> </td> <td colspan="2"
valign="middle" bgcolor="#33A6B3"> <center> <font
size="7" color="#E2E2E2"> Precious
Moments</font> <font size="7"
color="#E1F9FB"><?php echo " #:" .$item_num;
?> </font> </center> </td> </tr> <tr>
<td colspan="3" bgcolor="#0786AB"> <table
width="100%" border="0" cellspacing="0"
cellpadding="0"> <tr> <th scope="col"
align="center" width="85%"> <center> <font
size="+2" face="Georgia, Times New Roman, Times, serif"
color="#DBE4FD"> Title: </font> <b><font
color="#FFFFFF" size="+2"><?php echo $title; ?>
</font></b> </center> </th> <th
scope="col" align="center" rowspan="15%"><a
href="index.php">Home</a></th> </tr> </table>
</td> </tr> <tr>
<td align="justify" bgcolor="#E2E2E2"> Year: <font
color="#0000FF"><?php echo $year; ?> <br> <hr
color="#2C3785"></font> Mark: <font
color="#0000FF"><?php echo " $mark";
?></font> </td> <td width="231"
align="justify" bgcolor="#E2E2E2"> Original Box (yes/no):
<font color="#0000FF"><?php echo $box;
?></font><br> <hr
color="#2C3785"> Original Tags: <font
color="#0000FF"><?php echo " $tags";
?></font> </td> <td width="262"
align="right" bgcolor="#E2E2E2"> Price: <font
color="#0000FF"><b><?php echo "$" .$price;
?></font><br> Shipping: <font
color="#0000FF">$6.50</font><br> Shipping for each
additional item <font color="#0000FF">$1.50</font>
</td> </tr> </table>
<table
width="600" border="3" bordercolor="#0786AB">
<tr>
<td bgcolor="#DBE4FD">
<center><img
src="images/<?php echo $item_num;
?>.jpg"></center>
</td>
<td
width="289" valign="top" bgcolor="#DBE4FD">
<b>REMARKS:</b><br>
<?php echo
"" .$remarks; ?>
</td>
</tr>
</table>
</center>
</body> | |
|
3-
the Code of
db_functions.php |
<?php
function
db_connect() { // change to mysql_pconnect('yourhost',
'yourusername', 'yourpassword')or mysql_connect(...) $result =
mysql_pconnect('localhost', 'root', ''); if(!$result) return
false; if(!mysql_select_db('gallery')) // or whatever you called
your database return false;
return
$result; } | |
|
|
|
in Dreamweaver, select or open (php) files, Go
to File -> Preview in Browser -> IExplore or chrome, to Show
and display the Search Operations... |
index.php |
|
|
Click any Pictures - (Example: Young Girl With
Clock and Moust) to Display details.php |
| |
|
|
|
|
|