1. Trang chủ
  2. » Công Nghệ Thông Tin

Adobe Dreamweaver CS3 Unleashed- P26 ppt

50 149 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Adobe Dreamweaver Cs3 Unleashed
Trường học University of Example
Chuyên ngành Web Development
Thể loại Thesis
Năm xuất bản 2007
Thành phố Example City
Định dạng
Số trang 50
Dung lượng 1,02 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Select the Page from Template category, pick the VectaCorp site, where represents the server model you're working with ASP, ColdFusion, or PHP, choose the template option, and click Cre

Trang 1

Save your work as admin.asp, admin.cfm, or admin.php, depending on the server model you are working

with Now test the results in the browser by pressing F12 (Option+F12) The result looks similar to Figure25.30

Figure 25.30 Five records are shown in the dynamic table.

Trang 2

The Recordset Navigation Bar

Now that you have a dynamic table with data, you can use the Recordset Navigation Bar data object toinclude pagination features, much like the way we did in the previous chapter Rather than inserting fourseparate Paging server behaviors along with four separate Show Region server behaviors, as was done inthe previous chapter, however, you can use the Recordset Navigation Bar data object to accomplish the task

in a few simple clicks To insert a Recordset Navigation Bar, follow these steps:

1. Place your cursor just below the dynamic table you created in the preceding section and select Insert,Data Objects, Recordset Paging, Recordset Navigation Bar The Recordset Navigation Bar dialog

appears

2. Make sure that the rsProducts option is selected from the Recordset menu

3. Choose the Text option button from the Display Using option button group

4. Click OK The navigation bar appears on the page similar to Figure 25.31 Notice how all four

navigational items are present The Show Region server behaviors that are attached to this data objectcause these items to shift from being visible to invisible, depending on where you are in the recordset

Figure 25.31 The navigation bar is inserted into your page.

[View full size image]

Trang 3

Save your work and test the results in the browser The result looks similar to Figure 25.32 Notice that youcan page through five records at a time.

Figure 25.32 You can now page through five records at a time.

Trang 4

Deleting Records

Up to this point, we've provided a mechanism for displaying and paging through the data contained in theEmployeeStore table We've merely provided an alternative method (using data objects) for functionalitythat was outlined in the previous chapter This section is where the functionality begins to change In thissection, we'll manually create a new column in the dynamic table, outlining functionality that will allow anadministrator to delete certain products from the EmployeeStore table To add this functionality, followthese steps:

1. Add a new column to the dynamic table by right-clicking the ItemID column and selecting InsertColumn from the Table submenu A new column appears to the left of the ItemID column

2. Place your cursor in the first cell of the second row and choose Insert, Form, Button A new button isinserted in the cell

3. Select the button and change the value to Delete in the Property inspector Also, select the Noneoption button from the Action option button group

4. With the button selected, choose Insert, Data Objects, Delete Record The Delete Record dialogappears

5. Choose the connVectaCorp option from the Connection menu

6. Choose the EmployeeStore option from the Delete from Table menu

7. Choose the rsProducts option from the Select Record From menu

8. Select the ItemID option from the Unique Key Column menu

9. Make sure that the form1 option is selected in the Delete by Submitting menu The formatted DeleteRecord dialog resembles Figure 25.33

Trang 5

Figure 25.33 Format the Delete Record dialog.

[View full size image]

Save your work and test the admin page in the browser by pressing F12 (Option+F12) Navigate a fewrecords and click the Delete button The page refreshes itself, and the selected row disappears Check theEmployeeStore table to confirm the deletion

Master Detail Page Set

The Master Detail Page Set data object is one of the most powerful objects built in to Dreamweaver Itenables you to create a single page with as many fields from the recordset as you like You can then makeone of the items linkable so that it hyperlinks to a detailed page, revealing more detailed information aboutthe linked item In our example, we'll use the Master Detail Page Set to link the ItemName field to a secondpage that provides more information about the selected item How much more information can we provide?Remember that we excluded the Description and ImageURL fields when we created the Recordset earlier inthe chapter Because these fields are relevant to the item, we'll make these visible in a detailed page towhich we'll link from the master page You can work with the Master Detail Page Set by following thesesteps:

1. Create a new page by selecting File, New The New Document dialog appears Select the Page from

Template category, pick the VectaCorp<technology> site, where <technology> represents the server

model you're working with (ASP, ColdFusion, or PHP), choose the template option, and click Create

2 Immediately save your page as admin_master.asp, admin_master.cfm, or admin_master.php,

depending on the server model you're using

3. Create a new recordset To do this, select Insert, Data Objects, Recordset The Recordset dialog

appears Enter the name rsProducts, select the connVectaCorp connection, choose the EmployeeStore

table, and select all the fields from the Columns list Click OK to create the new recordset

4. Select the Content Goes Here text in the Content editable region and delete it With your cursor still in

the Content editable region, choose Insert, Data Objects, Master Detail Page Set The Insert Detail Page Set dialog appears

Master-5. Make sure that the rsProducts option is selected from the Recordset menu

6. Select both the ItemDescription and ImageURL fields from the Master Page Fields list and click theRemove (–) button

7. Select the ItemName field from the Link to Detail From menu

Trang 6

8. Choose the ItemID option from the Pass Unique Key menu.

9. Choose the All Records option button from the Show option button group

10 Enter the value admin_detail.asp, admin_detail.cfm, or admin_detail.php (depending on the

server model you are using) in the Detail Page Name text box

11 Leave the Detail Page Fields list box the way it is The formatted Insert Master-Detail Page Set dialog

should resemble Figure 25.34

Figure 25.34 Configure the Insert Master-Detail Page Set dialog accordingly.

[View full size image]

12 Click OK You are immediately taken to the detail page (admin_detail is automatically created for youbecause that's the name you supplied in the Master Detail Page Set dialog) as shown in Figure 25.35.Save the page

Figure 25.35 The detail page shows all the fields you specified.

Trang 7

[View full size image]

13 Switch back to the admin_master.asp, admin_master.cfm, or admin_master.php page Notice that adynamic table along with a navigation bar and status are inserted for you

Save your work and test it in the browser Selecting the ItemName links you to the detail page for that item,revealing more detailed information about the item you selected

Trang 8

As you have progressed through the previous two chapters, you have seen the amazing capabilities thatDreamweaver contains as far as reusable components that not only simplify development but make it muchmore enjoyable and fun But it doesn't stop there As you'll see in the coming chapters, possibilities arevirtually limitless: We'll explore creating search functionality, working with a shopping cart, security anduser authentication, and more

Trang 9

Chapter 26 Integrating Search Functionality

IN THIS CHAPTER

Integrating a SQL Search

Creating a Search Page

Creating the Search Results Page

Globalizing the Search Functionality

As you have seen, a database exists for the sole purpose of storing data Tables exist to separate that datainto well-structured and meaningful blocks of information that can be accessed at any time in an orderedmanner Most successful websites exist because the information in those sites is relatively easy to access.When you search for a book on Amazon.com, for example, you expect to find it within seconds of being onthe site You type a book name, click Search, and the results appear in a well-structured and elegantmanner If you visit eBay's website in an effort to find that treasure someone might be auctioning off, youtype the name of the item you are looking for and select a form object, usually a Submit button, to performthe search It's safe to say that in today's application service provider business model, most companiesemploy some mechanism for allowing their users quick access to the data that powers the company

It's true that the Web took off with the inception of the modern search engine Companies such as Yahooand Google, for instance, fueled the medium we know as the World Wide Web by making accessible theinformation contained within billions of websites on the Internet Employing basic, filtered, and advancedmethods of searching, those companies and others powered the Internet into what we know it as today.This chapter focuses on the capability to integrate these search methods into your web application,

specifically providing your users with the capabilities to search for information that they need in your site

As you've done with the rest of the chapters in this book, you can work with the examples in this chapter bydownloading the files from www.dreamweaverunleashed.com Remember, you'll want to save the files forChapter 26 (not the folder) in the C:\Inetpub\wwwroot\VectaCorp<technology> directory, where

<technology> represents the server technology (ASP, ASPX, CFM, PHP) you plan to use Make sure thatyour site is also properly defined in Dreamweaver as well, including the appropriate server-side technologyyou plan to use in the Testing Server category

Integrating a SQL Search

Finding information in your database can be a simple or a complex process Depending on the searchcriteria, you can give your users the capability to narrow their searches as fine as a specific date range

Suppose that you wanted to find all employees in your database who have the name John Smith; you can

create a simple queryin Access that selects all the records in the Employees table where the name is

equivalent to the name John Smith Your SQL statement would look something like this:

SELECT Name FROM Employees WHERE Name = 'John Smith'

The result returns all the matching records Indeed, the Vecta Corp database is filled with information thatusers may want access to, including the following:

Employees— As an admin, you can perform a search on your Employees table to extract

employee-specific information including name, address, city, state, and so on

Trang 10

CreditCards— Again as an admin, you can perform a search on the CreditCards table to extract all the

users' credit cards

EmployeeStore— Probably the most important container of information, the EmployeeStore table can

be searched by an employee to narrow down an employee's search for a specific product

Orders— As an admin, you can perform a search to determine how many items you sold on a specific

day, week, or month You could also return a statistical analysis of those results so that you couldbetter understand the employees' ordering habits and possibly suggest products in the future

Furthermore, the shipping and receiving department might want to perform a search for all orders thatneed to be shipped on a specific day or that need to arrive at their destinations by a certain day Thisinformation can help you determine what kind of shipping services to add to the parcel

As you can see, just within the Vecta Corp database, there is plenty available to search on Whether you areapproaching the problem as an admin or an employee, the database ultimately is a warehouse of

information How you access that information is covered next

Trang 11

Chapter 26 Integrating Search Functionality

IN THIS CHAPTER

Integrating a SQL Search

Creating a Search Page

Creating the Search Results Page

Globalizing the Search Functionality

As you have seen, a database exists for the sole purpose of storing data Tables exist to separate that datainto well-structured and meaningful blocks of information that can be accessed at any time in an orderedmanner Most successful websites exist because the information in those sites is relatively easy to access.When you search for a book on Amazon.com, for example, you expect to find it within seconds of being onthe site You type a book name, click Search, and the results appear in a well-structured and elegantmanner If you visit eBay's website in an effort to find that treasure someone might be auctioning off, youtype the name of the item you are looking for and select a form object, usually a Submit button, to performthe search It's safe to say that in today's application service provider business model, most companiesemploy some mechanism for allowing their users quick access to the data that powers the company

It's true that the Web took off with the inception of the modern search engine Companies such as Yahooand Google, for instance, fueled the medium we know as the World Wide Web by making accessible theinformation contained within billions of websites on the Internet Employing basic, filtered, and advancedmethods of searching, those companies and others powered the Internet into what we know it as today.This chapter focuses on the capability to integrate these search methods into your web application,

specifically providing your users with the capabilities to search for information that they need in your site

As you've done with the rest of the chapters in this book, you can work with the examples in this chapter bydownloading the files from www.dreamweaverunleashed.com Remember, you'll want to save the files forChapter 26 (not the folder) in the C:\Inetpub\wwwroot\VectaCorp<technology> directory, where

<technology> represents the server technology (ASP, ASPX, CFM, PHP) you plan to use Make sure thatyour site is also properly defined in Dreamweaver as well, including the appropriate server-side technologyyou plan to use in the Testing Server category

Integrating a SQL Search

Finding information in your database can be a simple or a complex process Depending on the searchcriteria, you can give your users the capability to narrow their searches as fine as a specific date range

Suppose that you wanted to find all employees in your database who have the name John Smith; you can

create a simple queryin Access that selects all the records in the Employees table where the name is

equivalent to the name John Smith Your SQL statement would look something like this:

SELECT Name FROM Employees WHERE Name = 'John Smith'

The result returns all the matching records Indeed, the Vecta Corp database is filled with information thatusers may want access to, including the following:

Employees— As an admin, you can perform a search on your Employees table to extract

employee-specific information including name, address, city, state, and so on

Trang 12

CreditCards— Again as an admin, you can perform a search on the CreditCards table to extract all the

users' credit cards

EmployeeStore— Probably the most important container of information, the EmployeeStore table can

be searched by an employee to narrow down an employee's search for a specific product

Orders— As an admin, you can perform a search to determine how many items you sold on a specific

day, week, or month You could also return a statistical analysis of those results so that you couldbetter understand the employees' ordering habits and possibly suggest products in the future

Furthermore, the shipping and receiving department might want to perform a search for all orders thatneed to be shipped on a specific day or that need to arrive at their destinations by a certain day Thisinformation can help you determine what kind of shipping services to add to the parcel

As you can see, just within the Vecta Corp database, there is plenty available to search on Whether you areapproaching the problem as an admin or an employee, the database ultimately is a warehouse of

information How you access that information is covered next

Trang 13

Creating a Search Page

In Chapter 22, "A Database Primer," you learned how to display dynamic data to the user You created aquery and integrated that query into your application using a server behavior that presented dynamic data.The problem with that approach is that it's hard-coded, meaning that the data the user ends up seeingalways remains the same What if your users don't want to see what you are choosing to present to them?Fortunately for you, you can allow your users to perform a search in your site based on criteria they specifythrough the use of form objects, recordsets/Datasets, and variables/parameters Before we jump ahead,let's dissect a common approach to creating search functionality Figure 26.1 shows the Amazon websiteand the search form you would use to search for a book

Figure 26.1 Most large websites employ some way of allowing their users to search for

information.

[View full size image]

Suppose that you have a database with a list of book titles The user of the website types a book name; thevalue of that text box is dynamically appended to a WHERE or a LIKE clause in a SQL statement The

database is then queried, and the results are presented to the user in a well-structured manner This kind ofintuitive functionality isn't limited to large companies such as Amazon and eBay You, too, can createfunctionality such as this using Dreamweaver To create your own basic SQL-based search page, regardless

of server model, follow these steps:

Trang 14

1. Create a new page by selecting File, New The New Document dialog appears Select the Page fromTemplate category, select your defined site, choose the template called template, and click Create Anew page is created from the template.

2 Immediately save the page as search.asp, search.aspx, search.cfm, or search.php, depending on

the server model you're using

3. Select the Content Goes Here text in the Content editable region and delete it.

4. With your cursor still in the editable region, choose Insert, Form, Form With the form selected, change

the value of the Action text box in the Properties Inspector to read search_results.asp,

search_results.aspx, search_results.cfm, or search_results.php, depending on the server model

you're using Make sure that the GET value is selected from the Method menu This configurationcauses the value the user enters in the text field to be passed along with the URL in the address bar(more on this later)

5. Insert a text field form object by selecting Insert, Form, Text Field With the text field selected, enter

the value txtSearch into the Name text box in the Property inspector.

6. Place your cursor next to the text field and insert a Submit Button form object into the form by

choosing Insert, Form, Button Change the Value text field in the Properties Inspector to read Search.

The result is shown in Figure 26.2

Figure 26.2 Create a new search page by adding the necessary Text Field and Submit

Button form objects.

[View full size image]

Save your work and test the results in the browser Enter a value and click the Search button As Figure26.3 shows, the value you enter into the text field is passed along with the URL in the address bar

Trang 15

Figure 26.3 Enter a value in the search text box and click Search The value is passed along with

the URL in the address bar.

[View full size image]

Figure 26.3 shows the value being searched on displayed in the address bar as a parameter appended to theURL string Although you won't be able to see the result in Figure 26.3, the page won't actually return aresult just yet What we need to do next is capture this parameter being passed along the address bar andre-query the database based on the value Let's do that next

Trang 16

Creating the Search Results Page

Now that the search page has been created, you'll want some way of collecting the value of the user's inputand processing the result of the search The search results page is where all the work is done The searchresults page must contain the following components for the search to be processed correctly:

The recordset or Dataset that represents the table being searched

The proper variables/parameters to capture the user's input from the search page

Dynamic text to display the result of the search to the user

Remember that a recordset/DataSet is always used to capture the results of the table information To create

a new recordset or DataSet for the search results page, follow these steps:

1. Create a new page by selecting File, New The New Document dialog appears Select the Page fromTemplate category, select your defined site, choose the template called template, and click Create Anew page is created from the template

2 Immediately save the page as search_results.asp, search_results.aspx, search_results.cfm, or search_results.php, depending on the server model you're using.

3. Select the recordset (or DataSet if you're working in ASP.NET) option from the Bindings panel's Add(+) menu The Recordset/DataSet dialog box appears

4 Click the Advanced button Name the recordset/DataSet rsSearch (or dsSearch if you're working in

ASP.NET)

5. Select the connVectaCorp option from the Connection menu

6. You can either manually construct your SQL query by typing the code directly into the SQL text box, oryou can select the appropriate fields from the Database Items selection box For now, simply add thefollowing code to the SQL text box:

SELECT * FROM EmployeeStore

WHERE ItemName = "Vecta Corp Shirt"

Notice that the value we're appending to the WHERE clause of the SQL statement is the text Vecta CorpShirt The completely formatted Recordset/DataSet dialog resembles Figure 26.4

Figure 26.4 Create the hard-coded query to extract a single record from the

database.

[View full size image]

Trang 17

7. Click the Test button The results, as shown in Figure 26.5, show the data for the Vecta Corp Shirt.

Figure 26.5 The result for the Vecta Corp Shirt is shown in the Test SQL Statement

window.

[View full size image]

Although the query seems to work perfectly, it's still not dynamic to the user As things stand now, theVecta Corp Shirt value always appears as the searched item The next section introduces you to working

with variables (also known as parameters if you're working in ASP.NET or ColdFusion) Variables/parameters

allow you to capture the users' input and ultimately make the search much more dynamic by varying theresult based on the parameter being passed in

Working with Variables in ASP and PHP

Up to this point, we've yet to discuss the topic variables Variables in Dreamweaver's Recordset dialog allowyou to capture user information from sessions, form requests, cookies, and application variables Variableslet you work dynamically by passing values from one page to another If you take the search page as anexample, a user submits the input in a form object to the search results page In the search results page, apiece of functionality must be added to capture that input so that it can be automatically appended to theSQL statement's WHERE clause In the ASP and PHP server models, that functionality is called a variable.

Trang 18

The ASP and PHP server models support variables; the ASP.NET and ColdFusion server models

support parameters Dedicated sections to both ASP.NET and ColdFusion are outlined next

Variables in Dreamweaver enable you to capture the data being sent from a previous page, store it, andthen use it at any time in the current page Variables contain four properties:

Name— The physical name of the variable.

Type— The data type associated with the type of data being stored in the database table.

Default Value— A default value to be assigned to the variable so that its value is never empty at

runtime

Runtime Value— The value to assign the variable.

You can set up a variable to capture the user's input from the search page by following these steps:

1. With the Recordset dialog still open in Advanced mode, add a variable to the variables list by selectingthe Add (+) button The Add Parameter dialog appears The variable should contain the followingproperties based on the server technology you are using (ASP or PHP):

Model Name Type Default

Value

Runtime Value

ASP Search Text abc Request.QueryString("txtSearch")

Note

Notice that we entered the value abc as the default value Because this is a required

value, the text abc guarantees that at least a value is sent across at runtime.

2. To capture requests made from a form via POST in ASP, you use the Form collection of the Requestobject or Request.Form followed by the name of the text box name within quotes To capture requestsmade from a form via GET, you use the QueryString collection of the Request object or

Request.QueryString followed by the name of the parameter that will be coming across the browser'saddress bar within quotes In PHP, it's simply a matter of enclosing the name of the form object with

the # symbol Click OK to close the Add Parameter dialog.

Trang 19

3. Modify the SQL statement as follows:

SELECT * FROM EmployeeStore

WHERE ItemName LIKE '%Search%'

4. As you can see, you want to use the keyword LIKE followed by the name of the variable you justcreated (Search) Also, we use the % operator as a way of retrieving all the values beginning andending with the value we're passing in as a parameter The result of the completely formatted

Recordset dialog should resemble Figure 26.6

Figure 26.6 Format the SQL statement in the Recordset dialog to accept the Search

variable as a parameter.

[View full size image]

5. Click OK The new recordset appears in the Bindings panel

6. Add all the dynamic text elements to the page, dragging the fields from the recordset into their

respective positions on the page You might also want to add captions for the field names In addition,drag the Total Records field into the header so that users are aware of how many records the searchproduced (total record count isn't directly available in the PHP server model If you want to display atotal record count in the PHP model, choose the Add (+) button in the Server Behaviors panel andchoose the Display Total Records option from the Display Record Count submenu) Figure 26.7 showsthe result of the dynamic text and total field additions

Figure 26.7 Add the fields from the recordset as dynamic text Under the ASP server model, you can also add the total number of records the search produced.

Trang 20

[View full size image]

Save your work and test the results in the browser by pressing F12 (Option+F12) Type the value Vecta Corp Shirt and click Submit As you'll see, the search produces a filtered result (1 record) based on the

value entered in the search text box The results are made possible because of the variable The variablecaptured the results of the request sent by the form's submission The variable was then appended to theSQL statement, which caused the dynamic search for the object's value

Working with Parameters in ASP.NET

Similar to the ASP server model, the search functionality can easily be created using ASP.NET The

difference between ASP/PHP and ASP.NET, however, lies in how we store and use the value that's beingappended to the URL in the address bar As you saw in the previous section, variables are the method usedfor collecting, storing, and then subsequently reusing the value coming across In the ASP.NET server

model, we use parameters instead of variables Like the variables we used in the ASP and PHP models,

parameters are the mechanism used for dynamically passing and using values coming from one page to theother Parameters in ASP.NET support the following three properties:

Name— The physical name of the parameter.

Type— The data type associated with the type of data being stored in the database table.

Value— The value to assign the variable This value is dynamically constructed using an intuitive Build

dialog

Now that the DataSet has been created and the SQL statement has been generated, you'll want to

dynamically change the value that appears just after the LIKE keyword Essentially, that value becomes aparameter, meaning that rather than using a variable to store the value being sent across, a parameter ispassed to the SQL statement dynamically To create a new parameter for the SQL statement, follow thesesteps:

Trang 21

1. With the DataSet dialog still open in Advanced mode, add a parameter to the parameters list byselecting the Add (+) button The Add Parameter dialog appears.

2 Type the name txtSearch into the Name text box.

3. Select the Char option from the Type menu

4. Click the Build button The Build Value dialog appears

5. Make sure that the value txtSearch exists in the Name text box

6. Choose the URL Parameter option from the Source menu

7 Type the value abc into the Default Value text box The formatted Build Value dialog resembles Figure26.8

Figure 26.8 Build the parameter's value using the Build Value dialog box.

8. Click OK to close the Build Value dialog The Value text box in the Edit Parameter dialog is now

populated with a conditional expression similar to Figure 26.9

Figure 26.9 The Value text field in the Parameter dialog is populated with a

conditional expression.

[View full size image]

Trang 22

9. Click OK to close the Edit Parameter dialog Notice that the parameter is added to the Parameters list

in the DataSet dialog box If you need to reopen the Edit Parameter dialog to make changes, click theEdit button

10 Modify the SQL statement to accept a parameter In ASP.NET, this is done by appending the LIKE

keyword followed by the ? symbol to the WHERE clause as follows:

SELECT * FROM EmployeeStore

WHERE ItemName LIKE ?

The result of the completely formatted DataSet dialog should resemble Figure 26.10

Figure 26.10 Format the SQL statement in the DataSet dialog to accept the

parameter.

[View full size image]

Trang 23

11 Click OK The DataSet appears in the Bindings panel.

12 Assuming search_results.aspx is already open, go ahead and add all the dynamic text elements tothe page, dragging the fields from the Dataset into their respective positions on the page You mightalso want to add captions for the field names Figure 26.11 shows the result of the dynamic textadditions

Figure 26.11 Add the fields from the DataSet as dynamic text.

[View full size image]

Trang 24

Save your work and test the results in the browser by pressing F12 (Option+F12) Type the value Vecta Corp Shirt and click Submit As you'll see, the search produces a filtered result (1 record) based on the

value entered in the search text box The results are made possible because of the parameter The

parameter captured the results of the request when the form was submitted The parameter was thenappended to the SQL statement, and the exact result based on the filtered criteria was returned

Working with Parameters in ColdFusion

Similar to the ASP, ASP.NET and PHP server models, search functionality for our Vecta Corp site can easily

be created using the ColdFusion server model The difference between ColdFusion and the other servermodels, however, lies in how we store and use the value that's coming across, appended to the URL in theaddress bar As you saw in the previous two sections, variables and parameters were used for collecting,storing, and then subsequently reusing the value coming across In the ColdFusion server model, however,variables and parameters are not necessary Instead we can dynamically append to the WHERE clause of the

SQL statement the value of the form name as a parameter, enclosed with # symbols To demonstrate this,

let's build the search functionality in ColdFusion by following these steps:

Trang 25

1. With the Recordset dialog box still open in Advanced mode, modify the SQL statement to accept the

form object's name enclosed with # symbols in the WHERE clause as follows:

SELECT * FROM EmployeeStore

WHERE ItemName LIKE '#txtSearch#'

In this case, the txtSearch form name is appended to the WHERE clause as a parameter ColdFusion issmart enough to check either the HTTP headers or the address bar for a form object that matches theparameter called txtSearch

2. Click OK The recordset appears in the Bindings panel

3. Add all the dynamic text elements to the page, dragging the fields from the recordset into their

respective positions on the page You might also want to add captions for the field names Figure 26.11shows the result of the dynamic text additions (shown within an ASP.NET page)

Save your work and test the results in the browser by pressing F12 (Option+F12) Figure 26.12 shows the

search result when I type the value Vecta Corp Shirt and click Submit.

Figure 26.12 In this example, we searched for Vecta Corp Shirt and the results came back with a

match.

[View full size image]

As you can see, the search produced a filtered result (1 record) based on the value I entered in the searchtext box

Repeating Regions

Now that your application has search capabilities, you might want to allow the user to see more than oneitem returned from the search at a time For now, our search works fine as is because we're performing asearch (Vecta Corp Shirt) that returns only one result from the EmployeeStore table But what if the user

performed a search on just the words Vecta Corp? In this case, our search would return multiple results because nearly every item in the EmployeeStore table begins with the words Vecta Corp But would it really

Ngày đăng: 01/07/2014, 19:20