This series of the videos explains how to create Photo Gallery using PHP, MySQL, ImageMagic and jQuery. Using PHP you will be able to add, modify and populate data stored on the MySQL Database and display records of all images on the page. ImageMagic will help us to resize and crop images to the relevant dimentions, while jQuery will provide the support in the presentation of the gallery. The last two chapters are dedicated to adding the earlier created gallery to our Content Management System. Over 4 hours of videos!!!

Dreamweaver tutorials

 
  • Link Exchange System with Dreamweaver CS3
  • Search engine

To create a search engine open links_list.php and in Code view create a new line after <p id="ptitle">Links</p> (Fig. 87).

New paragraph with Dreamweaver CS3
Fig. 87

Now go to Design view and from the Insert panel choose Forms tab and click Form button to insert a form into our page (Fig. 88).

Insert form with Dreamweaver CS3
Fig. 88

With form still selected double click Ctrl+T. This will bring up a form Edit tag option (Fig. 89). Change the id="form1" to id="forminsert" and press Enter on your keyboard. Save the file.

Rename the id of the form with Dreamweaver CS3
Fig. 89

Go to Code view and place the cursor in between the <form></form> tags (Fig. 90).

Place cursor inside the form in Dreamweaver CS3
Fig. 90

From the Insert panel choose Layout tab and click Table to insert table (Fig. 91).

Create table in Dreamweaver CS3
Fig. 91

In the new window choose:
Rows: 1
Columns: 4
leave Table width: blank
Border thickness: 0
Cell padding: 0
Cell spacing: 0
Header None
Caption: Search for Link

Leave all remaining options as default (Fig. 92).

Set up table in Dreamweaver CS3
Fig. 92

Add id="tblinsert" after cellpadding="0" of the <table> tag (Fig. 93).

Add id tag to the table in Dreamweaver CS3
Fig. 93

Now go to the Design view and place your cursor in the second cell of the table
(Fig. 94).

Place cursor inside of the table in Dreamweaver CS3
Fig. 94

Now from the Forms tab of the Insert panel choose Text Field (Fig. 95).

Insert text field
Fig. 95

In the new window type the following:
ID: keyword
Label: Search for:
Style: choose Attach label using 'for' attribute
Position: choose Before form item
Click OK to insert Text Field (Fig. 96).

Text field properties
Fig. 96

Now go to Code view and move <label for="keyword">Search for:</label> to the first table cell (in between the <td></td> tags) like in Fig. 97.

Move text field to the first table cell
Fig. 97

Now change the <td><label for="keyword">Search for:</label></td> tags of the first cell into <th><label for="keyword">Search for:</label></th>.

Go to Design view and now, before we move on to add a drop down menu item we will first create a recordset which will populate all categories currently available in the database.
In the Server Behaviors tab of the Application panel click + sign and choose Recordset (Fig. 98).

Create recordset
Fig. 98

In the new window type the following:
Name: rsCategories
from Connection: choose conndb
from Table: choose tbl_categories
Columns: select All
and in the Sort: choose catname and Ascending
Click OK to close the window and save the file (Fig. 99).

Recordset properties
Fig. 99

Place your cursor in the third cell and click List/Menu from the Forms tab in the Insert panel.

Insert drop down menu
Fig. 100

In the new window type:
ID: categ
leave Label: blank
in Style: select No label tag and leave the remaining options as default (Fig. 101).

Drop down menu properties
Fig. 101

With the drop down menu (List/Menu) still selected click Dynamic button in the Properties panel (Fig. 102).

Dynamic drop down menu
Fig. 102

In the new window choose
Menu: "categ" in form "form1"
Options from recordset: rsCategories
Values: catid
Labels: catname
finally click OK to apply changes (Fig. 103).

Dynamic data selection
Fig. 103

Drop down menu displays now all of our categories from the database.
You can test this page in the browser and you will be able to see our categories in the newly created menu. We still need to do some tweaking with it but let's just finish our form and we will get back to this in just a minute.

Now place your cursor in the last - fourth cell and from the Forms tab of the Insert panel choose Button (Fig. 104).

Select button
Fig. 104

In the Accessibility window leave all fields blank and for Style select No label tag. Click OK to insert the button (Fig. 105).

Button properties
Fig. 105

Ensure that our new button has id="button" assign to it by selecting it in the Design view and pressing Ctrl+T (Fig. 106). Dreamweaver should do it already for you. Press Enter on your keyboard and save the file.

Apply id to the button
Fig. 106

Up to now we have been purely using Dreamweaver tools and extensions to create all functionality on our site.
Now we will get dirty and start doing some coding - but don't worry - it's nothing major.

First we will make some amendments to our drop down menu. We need to add one option which will give us the result for all categories not just one which is currently selected.
To do this go to Code view, identify the line which starts with
<td><select name="categ" id="categ"> and create a new line underneath
(Fig. 107).

Identify form element
Fig. 107

In the new line type the following:

<option value="">All Categories</option>

Now if you test it in your browser you should see an extra option in the drop down menu which says All Categories.

In the <form> tag change method="post" to method="get" and change action="" to action="<?php echo $_SERVER['PHP_SELF']; ?>" so it looks like in Fig. 108.

Apply changes to the form
Fig. 108

Also, just to make our URL more readable when filtering our searching let's remove name="button" from our button so it shows as in Fig. 109.

Remove button name
Fig. 109

Sticky form fields
Sticky form fields are preserving user input after page reloads.

To create sticky form fields first identify the line which says:

<input type="text" name="keyword" id="keyword" />

After id="keyword" type the following:

<?php if (isset($_GET['keyword'])) { echo 'value="' .$_GET['keyword']. '"'; } ?>"

Now the this form field should look as in Fig. 110.

Sticky form fields
Fig. 110

Next step will be to apply sticky form fields to our drop down menu.
Identify the line which says:

<option value="">All Categories</option>

and after value="" type the following:

<?php if (isset($_GET['categ']) && $_GET['categ'] == "") { ?>
selected="selected"
<?php } ?>

Now apply the same to the other option in our drop down menu.
Find the line which reads:

<option value="<?php echo $row_rsCategories['catid']?>"><?php echo $row_rsCategories['catname']?></option>

After value="<?php echo $row_rsCategories['catid']?>" create a new line and type the following:

<?php if (isset($_GET['categ']) && $_GET['categ'] == $row_rsCategories['catid']) { ?>
selected="selected"
<?php } ?>

Now our entire search form should read as follow:

<form id="forminsert" name="form1" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="0" cellspacing="0" cellpadding="0" id="tblinsert">
<caption>
Search for Link
</caption>
<tr>
<th><label for="keyword">Search for:</label></th>
<td>
<input type="text" name="keyword" id="keyword"
<?php if (isset($_GET['keyword'])) {
echo 'value="' .$_GET['keyword']. '"'; } ?> />
</td>
<td><select name="categ" id="categ">
<option value=""
<?php if (isset($_GET['categ']) && $_GET['categ'] == "") { ?>
selected="selected"
<?php } ?>
>All Categories</option>
<?php
do {
?>
<option value="<?php echo $row_rsCategories['catid']?>"
<?php if (isset($_GET['categ']) && $_GET['categ'] == $row_rsCategories['catid']) { ?>
selected="selected"
<?php } ?>
><?php echo $row_rsCategories['catname']?></option>
<?php
} while ($row_rsCategories = mysql_fetch_assoc($rsCategories));
$rows = mysql_num_rows($rsCategories);
if($rows > 0) {
mysql_data_seek($rsCategories, 0);
$row_rsCategories = mysql_fetch_assoc($rsCategories);
}
?>
</select></td>
<td><input type="submit" id="button" value="Submit" /></td>
</tr>
</table>
</form>

You can test it in the browser. Whatever you type in the first field should stay there when you press Submit button.
The same applies to the dropdown menu. Choose any of the categories and press the button. Drop down menu should preserve your chosen category.

Next we will need to modify our SQL statement to ensure that it takes our searching criteria into account when pulling out the records from the database and displays them on the page.

Scroll up to the top and find the line which says:

mysql_select_db($database_conndb, $conndb);

Place your cursor at the end of this line and create two new lines by pressing Enter on your keyboard twice.
Now type the following:

// Search engine functionality
if ($_GET['keyword'] || $_GET['categ']) {

$key = $_GET['keyword'];
$categ = $_GET['categ'];

In the next line you should see the following statement:

$query_rsLinks = "SELECT * FROM tbl_links ORDER BY linkdate DESC";

Copy it and paste right under itself.
Now modify the first copy of the statement so it reads:

$query_rsLinks = "SELECT * FROM tbl_links WHERE (tbl_links.linkemail LIKE '%$key%' OR tbl_links.linktitle LIKE '%$key%' OR tbl_links.linkurl LIKE '%$key%') AND tbl_links.linkcat LIKE '$categ' ORDER BY tbl_links.linkdate DESC";
} else {

Lastly after the second copy of the statement type:

}

Now the modified code should read:

$startRow_rsLinks = $pageNum_rsLinks * $maxRows_rsLinks;

mysql_select_db($database_conndb, $conndb);

// Search engine functionality
if ($_GET['keyword'] || $_GET['categ']) {

$key = $_GET['keyword'];
$categ = $_GET['categ'];

$query_rsLinks = "SELECT * FROM tbl_links WHERE (tbl_links.linkemail LIKE '%$key%' OR tbl_links.linktitle LIKE '%$key%' OR tbl_links.linkurl LIKE '%$key%') AND tbl_links.linkcat LIKE '%$categ%' ORDER BY tbl_links.linkdate DESC";

} else {

$query_rsLinks = "SELECT * FROM tbl_links ORDER BY linkdate DESC";

}

$query_limit_rsLinks = sprintf("%s LIMIT %d, %d", $query_rsLinks, $startRow_rsLinks, $maxRows_rsLinks);
$rsLinks = mysql_query($query_limit_rsLinks, $conndb) or die(mysql_error());
$row_rsLinks = mysql_fetch_assoc($rsLinks);

Try to test your page in the browser.

The only last thing we need to do is to create a recordset paging in case we have more than just 30 records which we have set up as a limit for our page.
Because we have modified our rsLinks recordset, Dreamweaver does not display it in its Server Behaviors window. On this occasion we will simply copy and paste the following content after the line which reads
<?php } // Show if recordset empty ?>:

<?php if ($totalRows_rsLinks > $maxRows_rsLinks) { ?>
<p id="paging">
<?php if ($pageNum_rsLinks > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsLinks=%d%s", $currentPage, 0, $queryString_rsLinks); ?>"><<</a>
<?php } // Show if not first page ?>
<?php if ($pageNum_rsLinks == 0) { // Show if first page ?>
<span class="inactive"><<</span>
<?php } // Show if first page ?>
<?php if ($pageNum_rsLinks > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsLinks=%d%s", $currentPage, max(0, $pageNum_rsLinks - 1), $queryString_rsLinks); ?>"><</a>
<?php } // Show if not first page ?>
<?php if ($pageNum_rsLinks == 0) { // Show if first page ?>
<span class="inactive"><</span>
<?php } // Show if first page ?>
<?php if ($pageNum_rsLinks < $totalPages_rsLinks) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsLinks=%d%s", $currentPage, min($totalPages_rsLinks, $pageNum_rsLinks + 1), $queryString_rsLinks); ?>">></a>
<?php } // Show if not last page ?>
<?php if ($pageNum_rsLinks >= $totalPages_rsLinks) { // Show if last page ?>
<span class="inactive">></span>
<?php } // Show if last page ?>
<?php if ($pageNum_rsLinks < $totalPages_rsLinks) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsLinks=%d%s", $currentPage, $totalPages_rsLinks, $queryString_rsLinks); ?>">>></a>
<?php } // Show if not last page ?>
<?php if ($pageNum_rsLinks >= $totalPages_rsLinks) { // Show if last page ?>
<span class="inactive">>></span>
<?php } // Show if last page ?>
</p>
<?php } ?>

This step completes this section where we have learned how to create a search engine for our page.
In next section I will explain how to create Edit Link page.

<< Manage Links Page | Edit Link Page >>

 
  • Thank you for subscribing to our newsletter.
  • To complete registration please click on the link in the email which has been sent to you.
  • Invalid first name
  • Invalid last name
  • Invalid email address

Website Design Company | Website Design Company Sussex | Website Design Company Chichester | Website Design Packages
Tutorials Resources | Articles | Contact | Vector
© Web Design Tutorials – Sebastian Sulinski