Adobe Dreamweaver CS3 Unleashed- P26

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:50

0
220
lượt xem
21
download

Adobe Dreamweaver CS3 Unleashed- P26

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Adobe Dreamweaver CS3 Unleashed- P26: The good news is Dreamweaver provides numerous windows, panels, inspectors, and toolbars for streamlining the way you build websites. The bad news, unfortunately, is that Dreamweaver provides numerous windows, panels, inspectors, and toolbars for streamlining the way you build websites. Why so many windows, panels, and so on, Dreamweaver is unprecedented in the feature set it provides, allowing developers complete control when building websites and applications....

Chủ đề:
Lưu

Nội dung Text: Adobe Dreamweaver CS3 Unleashed- P26

  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 Figure 25.30. Figure 25.30. Five records are shown in the dynamic table. [View full size image]
  2. The Recordset Navigation Bar Now that you have a dynamic table with data, you can use the Recordset Navigation Bar data object to include pagination features, much like the way we did in the previous chapter. Rather than inserting four separate Paging server behaviors along with four separate Show Region server behaviors, as was done in the 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 object cause 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]
  3. Save your work and test the results in the browser. The result looks similar to Figure 25.32. Notice that you can page through five records at a time. Figure 25.32. You can now page through five records at a time. [View full size image]
  4. Deleting Records Up to this point, we've provided a mechanism for displaying and paging through the data contained in the EmployeeStore table. We've merely provided an alternative method (using data objects) for functionality that was outlined in the previous chapter. This section is where the functionality begins to change. In this section, we'll manually create a new column in the dynamic table, outlining functionality that will allow an administrator to delete certain products from the EmployeeStore table. To add this functionality, follow these steps: 1. Add a new column to the dynamic table by right-clicking the ItemID column and selecting Insert Column 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 is inserted in the cell. 3. Select the button and change the value to Delete in the Property inspector. Also, select the None option button from the Action option button group. 4. With the button selected, choose Insert, Data Objects, Delete Record. The Delete Record dialog appears. 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 Delete Record dialog resembles Figure 25.33.
  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 few records and click the Delete button. The page refreshes itself, and the selected row disappears. Check the EmployeeStore 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. It enables you to create a single page with as many fields from the recordset as you like. You can then make one of the items linkable so that it hyperlinks to a detailed page, revealing more detailed information about the linked item. In our example, we'll use the Master Detail Page Set to link the ItemName field to a second page 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 in the chapter. Because these fields are relevant to the item, we'll make these visible in a detailed page to which we'll link from the master page. You can work with the Master Detail Page Set by following these steps: 1. Create a new page by selecting File, New. The New Document dialog appears. 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 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 Master- Detail Page Set dialog appears. 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 the Remove (–) button. 7. Select the ItemName field from the Link to Detail From menu.
  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 you because 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.
  7. [View full size image] 13. Switch back to the admin_master.asp, admin_master.cfm, or admin_master.php page. Notice that a dynamic 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.
  8. Summary As you have progressed through the previous two chapters, you have seen the amazing capabilities that Dreamweaver contains as far as reusable components that not only simplify development but make it much more enjoyable and fun. But it doesn't stop there. As you'll see in the coming chapters, possibilities are virtually limitless: We'll explore creating search functionality, working with a shopping cart, security and user authentication, and more.
  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 data into well-structured and meaningful blocks of information that can be accessed at any time in an ordered manner. 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 on the site. You type a book name, click Search, and the results appear in a well-structured and elegant manner. If you visit eBay's website in an effort to find that treasure someone might be auctioning off, you type the name of the item you are looking for and select a form object, usually a Submit button, to perform the search. It's safe to say that in today's application service provider business model, most companies employ 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 Yahoo and Google, for instance, fueled the medium we know as the World Wide Web by making accessible the information contained within billions of websites on the Internet. Employing basic, filtered, and advanced methods 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 by downloading the files from www.dreamweaverunleashed.com. Remember, you'll want to save the files for Chapter 26 (not the folder) in the C:\Inetpub\wwwroot\VectaCorp directory, where represents the server technology (ASP, ASPX, CFM, PHP) you plan to use. Make sure that your site is also properly defined in Dreamweaver as well, including the appropriate server-side technology you 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 search criteria, 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 that users 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.
  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 could better 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 that need to be shipped on a specific day or that need to arrive at their destinations by a certain day. This information 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 are approaching the problem as an admin or an employee, the database ultimately is a warehouse of information. How you access that information is covered next.
  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 data into well-structured and meaningful blocks of information that can be accessed at any time in an ordered manner. 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 on the site. You type a book name, click Search, and the results appear in a well-structured and elegant manner. If you visit eBay's website in an effort to find that treasure someone might be auctioning off, you type the name of the item you are looking for and select a form object, usually a Submit button, to perform the search. It's safe to say that in today's application service provider business model, most companies employ 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 Yahoo and Google, for instance, fueled the medium we know as the World Wide Web by making accessible the information contained within billions of websites on the Internet. Employing basic, filtered, and advanced methods 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 by downloading the files from www.dreamweaverunleashed.com. Remember, you'll want to save the files for Chapter 26 (not the folder) in the C:\Inetpub\wwwroot\VectaCorp directory, where represents the server technology (ASP, ASPX, CFM, PHP) you plan to use. Make sure that your site is also properly defined in Dreamweaver as well, including the appropriate server-side technology you 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 search criteria, 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 that users 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.
  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 could better 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 that need to be shipped on a specific day or that need to arrive at their destinations by a certain day. This information 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 are approaching the problem as an admin or an employee, the database ultimately is a warehouse of information. How you access that information is covered next.
  13. Creating a Search Page In Chapter 22, "A Database Primer," you learned how to display dynamic data to the user. You created a query 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 seeing always 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 specify through 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 website and 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; the value 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 of intuitive functionality isn't limited to large companies such as Amazon and eBay. You, too, can create functionality such as this using Dreamweaver. To create your own basic SQL-based search page, regardless of server model, follow these steps:
  14. 1. Create a new page by selecting File, New. The New Document dialog appears. Select the Page from Template category, select your defined site, choose the template called template, and click Create. A new 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 configuration causes 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 Figure 26.3 shows, the value you enter into the text field is passed along with the URL in the address bar.
  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 the URL string. Although you won't be able to see the result in Figure 26.3, the page won't actually return a result just yet. What we need to do next is capture this parameter being passed along the address bar and re-query the database based on the value. Let's do that next.
  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 input and processing the result of the search. The search results page is where all the work is done. The search results 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 from Template category, select your defined site, choose the template called template, and click Create. A new 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, or you can select the appropriate fields from the Database Items selection box. For now, simply add the following 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 Corp Shirt. 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]
  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, the Vecta 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 the result 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 allow you to capture user information from sessions, form requests, cookies, and application variables. Variables let you work dynamically by passing values from one page to another. If you take the search page as an example, a user submits the input in a form object to the search results page. In the search results page, a piece of functionality must be added to capture that input so that it can be automatically appended to the SQL statement's WHERE clause. In the ASP and PHP server models, that functionality is called a variable.
  18. Note 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, and then 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 selecting the Add (+) button. The Add Parameter dialog appears. The variable should contain the following properties based on the server technology you are using (ASP or PHP): Model Name Type Default Runtime Value Value ASP Search Text abc Request.QueryString("txtSearch") PHP Search Text abc #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 Request object or Request.Form followed by the name of the text box name within quotes. To capture requests made 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's address 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.
  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 just created (Search). Also, we use the % operator as a way of retrieving all the values beginning and ending 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 search produced (total record count isn't directly available in the PHP server model. If you want to display a total record count in the PHP model, choose the Add (+) button in the Server Behaviors panel and choose the Display Total Records option from the Display Record Count submenu). Figure 26.7 shows the 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.
  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 variable captured the results of the request sent by the form's submission. The variable was then appended to the SQL 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 being appended to the URL in the address bar. As you saw in the previous section, variables are the method used for 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 the other. 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 a parameter, meaning that rather than using a variable to store the value being sent across, a parameter is passed to the SQL statement dynamically. To create a new parameter for the SQL statement, follow these steps:
Đồng bộ tài khoản