Give your website visitors a method to search and display results on your website. In this tutorial, I will demonstrate how to create a search page and a filtered results page.
- Dreamweaver CS3 or newer
- Data Bridge (alternately, DataAssist 2.0 or higher) installed and activated in Dreamweaver
- PHP site defined in Dreamweaver
- SQL sample files to use with this tutorial: blue_sky_music.sql
- PHP sample files to use with this tutorial: Start.zip
Using the Data Bridge Search Wizard, you will learn how to create a search page and a results page using recordsets. In addition to creating your advanced search functionality, this tutorial begins by walking you through 4 preparatory steps.
- Create a new site in Dreamweaver
- Create a database using phpMyAdmin
- Add sample files
- Create a database connection
Your first step is to create and define a dynamic site in Dreamweaver.
Detailed directions are found in these WebAssist tutorials:
Define a dynamic site in CS4
Define a dynamic site in CS5
Now that your site has been created, your next step is to create a database. In this tutorial, we will use the phpMyAdmin tool. phpMyAdmin is commonly used for managing MySQL databases.
- Open blue_sky_music.sql in a text editor such as Notepad or TextEdit
- Select all of the content (Ctrl or Cmd + A)
- Copy the content (Ctrl or Cmd + C)
- Save the file to your desktop (Ctrl or Cmd + S)
- Close your text editor
- In phpMyAdmin, choose the database you intend to work with from the Database menu list
- Open the SQL tab
- Paste the copied SQL script into the text field (Ctrl or Cmd + P)
- Click Go
- Confirm that your new table has been imported by clicking the Structure tab
Please refer to the following WebAssist tutorial for more help:
Import a .sql file
Now that a database has been created, you will add sample files to your site.
- Open Start.zip using Windows Explorer (Windows) or Finder (Mac)
- Extract and save to your desktop (Ctrl or Cmd + S)
- Open the Start folder
- Select all of the files (Ctrl or Cmd + A)
- Copy the files (Ctrl or Cmd + C)
- Paste them into the folder (see below) where you store your site's files (Ctrl or Cmd + P)
- Save (Ctrl or Cmd + S)
Note: The folder where you store your site's files is usually found in C:\xampp\htdocs if you are using Windows. But this path will differ if you chose to install to a different directory when you set up your testing server. On a Mac, the default location to place your files is /Applications/MAMP/htdocs. But this path will also differ if you chose to install to a different directory when you set up your testing server.
Please refer to the following WebAssist tutorials for more help:
Set up a test server on Windows
Set up a test server on Mac OS
Creating a database connection in Dreamweaver is your final preparatory step. A PHP database connection tells Dreamweaver that the current site is going to create PHP pages and refer to a specific database to store or display data.
- Go to the Databases panel in your Dreamweaver site
- Double-click on connBSM to open the MySQL Connection dialog box
Fill in the fields and perform the actions to complete the dialog box.
- Connection name: connBSM
- MySQL server: localhost
- Username: (fill in your username)
- Password: (fill in your password)
- Database: blue_sky_music (use Select to navigate to the file)
- Click Test to confirm a successful connection
- Click OK
Please refer to the following WebAssist tutorial for more help:
Create a PHP database connection
With the 4 preparatory steps finished, your next step is to create the advanced search functionality using the DataAssist Search Wizard. The DataAssist Search Wizard requires two pages to work, a search page and a results page.
Step 1: Create a recordset on the results page
DataAssist Search works by attaching itself to a recordset behavior that has already been applied to the page.
- In the Files panel, open Results.php
- In the Server Behaviors panel, select +
- Choose Recordset
- Enter rsItems in the recordset Name field
- Select your Connection
- Select items in the Table menu list
- Click OK
- Save the results page (Ctrl or Cmd + S)
Step 2: Create a recordset on the search page
This recordset is necessary since the category list references a different database table than the items table.
- In the Files panel, open Search.php
- In the Server Behaviors panel, click +
- Select Recordset
- Enter rsCat in the recordset Name field
- Select your Connection
- Select itemcategory in the Table menu list
- Click OK
- Save the search page (Ctrl or Cmd + S)
Step 3: Create the category search form
Now that both recordsets have been created, you can run the DataAssist Search Wizard. First, close Search.php and return to Results.php. Then go to the WebAssist category, select Database, and open the DataAssist Search Wizard.
- In Filter Data, select the rsItems Recordset
- In Search Page, select the Existing search page radio button
- Use the browse file icon to select Search.php
- In Search Form, select the New form radio button
- In the New form text field, enter SearchForm
- In the Editable region menu, select PageBody
- Click Next
The first search element to be added is a menu list that will provide category options.
- To add a new search element, click the + button
- In the search type list, select Exact Match
- Click Next
- In the Column menu, select ItemCatID
- In the Column type menu, select Number/Boolean
- Enter catSearch in the New form text field
- In the New form field menu list, choose Select
- Click Next
Step 4: Create the price range search fields
The next search element to be added is the price range search fields. The price range search inserts two form fields onto your page. The first is for specifying a minimum value and the second is to specify a maximum value. Keep in mind, when using a price range search, the contents of the database column being used must be numeric and should not contain any text or date information.
- Click the + button to create another search element
- In the Search type list, choose Price Range
- Click Next
- In the Column menu list, select ItemPrice
- Select the first New form field radio button
- Enter minPrice
- Select the second New form field radio button
- Enter maxPrice
- Make sure that Text is shown in both of the adjacent text fields
- Click Next
- Verify that two search elements have been added
- Click Next
- If you would like to modify the search, click Previous
- Or click Finish to close the DataAssist Search Wizard
- Save the page (Ctrl or Cmd + S)
Step 5: Customize the category menu list
Now that the DataAssist Search Wizard has finished, you should have three new form fields on your search page.
The next step is to customize the category menu list so that the appropriate categories are displayed.
- From the Files panel, open Search.php
- Select the category menu list
- From the Properties inspector, select the Dynamic button
- In the Options from recordset menu, select rsCat
- In the Values menu, select ItemCatID
- In the Labels menu, select ItemCatName
- To prevent a category being selected by default, click the + button in the Static options area
- Click once in the value area, and press Delete on your keyboard to remove the text
- In the Label field, enter Please choose a Category
- Click OK
Step 6: Define your search results
You will want to customize the results page to determine what results are displayed.
- From the Files panel, open Results.php
Notice that a simple table with four columns has already been created for this example.
- Place your cursor in the cell below the Product ID heading
- From the Bindings panel, expand Recordset (rsItems)
- Select ItemID
- Click Insert
- Repeat this step for the other 3 columns
- Place your cursor in the Name cell
- From the Bindings panel, select ItemName
- Click Insert
- Place your cursor in the Description cell
- From the Bindings panel, select ItemShortDesc
- Click Insert
- Place your cursor in the Price cell
- From the Bindings panel, select ItemPrice
- Click Insert
Note: If you wished to include additional results on your page, simply create additional columns in the table, and repeat these same steps.
Now you will create a repeat region to repeat the results so that more than the first search result is displayed.
- Place your cursor after the search table
- From the tag inspector, select the <tr> tag
- From the Server Behaviors panel, click +
- Select Repeat Region
- In the Repeat Region window, select the All records radio button
- Click OK
Step 7: Handle empty search results
Now that you have applied the search to your page, you will need to ensure that something friendly appears if no search results are found.
- Place your cursor after the results table
- Press Enter on your keyboard and type Sorry, no items matched your search criteria
- From the tag selector, select the <p> tag to highlight your newly entered text
- In the Server Behaviors panel, click +
- Select Show Region
- Choose Show Region if Recordset is Empty
- In Recordset, select rsItems
- Click OK
Next, to ensure that the results table will not display if there are no results, repeat this process.
- Place your cursor in the results table
- From the tag selector, select the <table> tag
- From the Server Behaviors panel, click +
- Select Show Region
- Select Show Region if Recordset is Not Empty
- In Recordset, select rsItems
- Click OK
- Save the page (Ctrl or Cmd + S)
Step 8: Conclusion
Your search page should now be properly configured.
Your results page should now be properly configured.
Press F12 to preview and test your advanced search functionality.
amr badawy: 10 Years, 4 Months, 2 Days, 10 Hours, 18 Minutes ago
When working on this performance, which shows the error
while executing onclick in WDAS_serverbehavior.htm a javascript error occurred
What is the solution
I hope to respond soon
Team WebAssist: 10 Years, 4 Months, 1 Day, 17 Hours, 20 Minutes ago
amr, Usually errors like this are some sort of installation glitch. Try the Fixing Common Issues section of this tutorial: http://www.webassist.com/tutorials/Common-installation-issues
If that doesn't work, you can seek technical support by clicking on Help in our main menu.