Dreamweaver MX Ultradev Exploration(2)
Author:Eve Cole
Update Time:2009-05-31 21:07:46
Dreamweaver MX Ultradev Explore (2) Display records in database
In the previous lecture, we mainly talked about setting up the database connection. Today we are going to start the actual implementation of the background application and obtain data from the database. The previous words are all preparation for today's work. The web pages we see today are basically dynamic. The so-called dynamic means that it is combined with a database to automatically update information. Retrieving data from the database is the most basic and the most commonly used dynamic method. Next we will retrieve the product information list from the Product table in the Northwind database through query.
Note that when setting up the site, please set Access in the Testing Server option to FTP or Local/Network (Figure 2-1), otherwise Bindings will not be available.
Figure 2-1
Select the Bindings tab in the Application panel on the right. Press the plus button (as shown in Figure 2-2)
Figure 2-2
In the Recordset dialog box, make detailed settings as follows:
Name:disProduct
Connection: northwind (this is the connection we established in the previous lecture, optional)
Table: Product (all tables in the database are listed here, we select Product)
Columns: It contains all the fields in the Product. If you select the Select radio button, then we can filter the fields. (As shown in Figure 2-3)
Figure 2-3
After the settings are completed, we can test it and press the Test button on the right. Isn’t it a surprise? All the data we need has been listed. The power of the tool is great! (As shown in Figure 2-4)
Figure 2-4
Click OK to return to the Recordset dialog box, and then click OK to return to the page. At this time, we can see the changes in the Binding tag, and the query named disProduct we created appears. I think everyone should easily think of objects after seeing this. It is very intuitive and much easier to understand than creating objects in code (as shown in Figure 2-5). Click the "+" sign next to it to expand it. In the Product table, All fields appear before your eyes. (As shown in Figure 2-6)
Figure 2-5
Figure 2-6
Our purpose is to display a product list on the page. In the following work, you will discover how easy it is to display things in the database on the page. You will once again feel the greatness of the tool.
Create a table with two rows and four columns on the page, and fill in the first row with: product name, unit quantity, unit price, and inventory (as shown in Figure 2-7). These are the fields we want to display on the page. In the next part, we will put the contents of the field in.
Figure 2-7
To select the fields expanded in Bindings, we first select the "Product Name" field, then click the mouse on the first column of the second row of the table to make the cursor flash in it, then return to the Bindings panel and click the insert button, (as shown in the figure) 2-8)
Figure 2-8
Insert the "unit quantity, unit price, and inventory" fields into the table in the same way (as shown in Figure 2-9). There is also a simpler method, that is, you can drag the fields to the place where you want to place them. The effect It's the same, and simpler. Okay, now look at the original code. If you are a beginner of Asp, let me tell you an experience. It is to look at the original code generated by mx, which will be of great help to you in learning Asp. Because you will find in the future that you can try to merge two pages together by simply adding a few lines of code, such as the login page. That is a story for another time. You will know as you read on.
Figure 2-9
Okay, now save your page and see the fruits of your labor in your browser. Don't tell me you don't know how to debug Asp pages! What is displayed? There is only one row of results. Isn’t it very disappointing to you? Haha, the record pointer has not moved, of course only the first line is displayed. Read on.
We are going to start talking about Server Behaviors. We can use it to achieve many functions. Let’s not talk about it for now. Let’s take a look at it. The problem we need to solve now is how to display all records. Select all cells in the second row of the table (Figure 2-10),
Figure 2-10
Click the "+" button on the Server Behaviors label, select Repeat Region in the drop-down menu, and select the All radio button in the Repeat Region dialog box. If you don't want to display all, you can also select the radio button above and enter the number you want to display. (As shown in Figure 2-11)
Figure 2-11
Press OK button to return. One more behavior appears in the Server Behaviors tab (Figure 2-12). Looking at the original code, you find that he just added a loop statement.
Figure 2-12
Save the changes and debug again. How about, whatever you set in (Figure 2-11) will come out. At this point today, you can review the following, which is mainly about creating queries. There are many tips in it.
to be continued……