Recently, in order to make full use of book resources and facilitate employee inquiries, the company decided to establish a book inquiry system on the company's intranet. Considering that the company does not have many books, only more than 1,000 volumes, and most of them are professional books, I decided to make two query conditions: one is to query based on the book category. The user only needs to select the corresponding category to display all the books in that category. Books, this is mainly for people who are not familiar with the company's books; the second is to query based on the book name. Users can quickly search for all books that meet the conditions as long as they enter the book name.
The plan has been decided, and the next question is what software to use and how to do it. Here, I chose the form of a web page, so that colleagues can query as long as they open the browser and enter the corresponding address. Therefore, I use Dreamweaver software (hereinafter referred to as dw), a powerful tool for web page production, acess for the database, and win98 and pws as the environment (Editor's note: For tutorials on the use of PWS, please refer to "In-depth Understanding of Microsoft Personal Server PWS One" and "In-depth Understanding of Microsoft Personal Server" Server PWS Part 2" "In-depth understanding of Microsoft Personal Server PWS Part 3" "In-depth understanding of Microsoft Personal Server PWS Part 4"). The official start of the gong is now.
Click here to download the source code for this tutorial.
First, set up the database:
1. Create a new folder under My Documents and name it "Institute". Of course, you can also create a new one elsewhere and give it another name.
2. Open acess, create a new database db1, and create two tables leibie and tushu. The contact field between the tables is "category name".
The table leibie structure has two fields:
(1) Category number, text type, field length is 6 digits, required field, blank strings are not allowed;
(2) Category name, text type, field length is 20 characters, required field, blank strings are not allowed.
The table tushu structure has nine fields:
(1) Number, text type, field length is 6 digits;
(2) Book title, text type, field length is 60 characters, required field, blank strings are not allowed.
(3) Author, text type, field length is 50 characters;
(4) Publisher, text type, field length is 60 characters;
(5) Edition, text type, field length is 15 digits;
(6) Unit price, currency type, 2 decimal places allowed, default value is 0 yuan;
(7) Category name, text type, field length is 20 characters, required field, blank strings are not allowed.
(8) Whether to lend, text type, field length is 4 digits, required field, blank string is not allowed to be entered, the default value is No.
(9) Remarks, remark type.
3. Enter various data according to the table structure.
Secondly, set up the site and connect to the database:
(1) Set up the site. Open dw, select new site under the site menu, and the site setting panel will pop up. Enter the site name into the institute, and the directory is the directory we just created, as shown in Figure 1. Select Asp VBScript for Server Model in the Testing Server option, and select Local/Network for Access. .
Figure 1
(2) Create a new web page. Because the query is a dynamic page, select Dynamic page and Asp VBScript in the pop-up panel, as shown in Figure 2. Press the create button to return to the page.
Figure 2
(3) Connect to the database. Expand the Application panel on the right, select the Databases tab, press the "+" button, and select Data Source Name (DSN), as shown in Figure 3.
Figure 3
(4) On the pop-up Data Source Name (DSN) panel (as shown in Figure 4), select the define... button to enter the ODBC data source manager, select the system DSN label, click the Add button, and select "Driver do Microsoft Access(*. mdb)" data driver, click the Finish button.
Figure 4
(5) Select the database path (the directory we just created) on the subsequent panel, select db1, and enter db1 as the data source name, as shown in Figure 5.
Figure 5 (6) Click the OK button to return to the ODBC Data Source Manager panel. Click the OK button again to return to the Data Source Name (DSN) panel. Click the test button. If the success panel as shown in Figure 6 pops up, it means that everything is ok and the database has been connected. Our new data source db1 will appear correspondingly in the Databases tab of the Application panel on the right.
Figure 6
Now that everything is ready, you can create a dynamic query web page.
1. Create a homepage. The home page is very simple, just create two query links, "Search by book category" links to chaxun.asp, "Search by book name" links to chaxun1.asp, these two web pages are the query web pages we will build below. Since the homepage does not require dynamic programming, it can be saved in htm format. The file is saved in the institute directory and named index, as shown in Figure 7.
Figure 7
2. Create a query web page by book category.
1. Create a new dynamic web page and name it chaxun.asp.
2. Create a record set. Select the Bindings tab in the Application panel on the right, press the plus button, and select Recordset (Query), as shown in Figure 8. The Recordset dialog box pops up. The settings inside are as shown in Figure 9. Name takes the default value Recordset1, and Connection selects the one we just created. Connect to db1. Because the book category is displayed, Table selects table leibie.
Figure 8
Figure 9 3. After the settings are completed, click the test button, and you can see that the contents of the leibie table are fully displayed. Click OK to return to the page. At this time, we can see the query named Recordset1 we just created displayed below the Binding label.
4. Enter the content displayed statically on the web page, as shown in Figure 10, in which the "return" link points to the homepage index.htm.
Figure 10
5. Click the "+" sign next to Recordset1 below the Binding label to expand the field. Press and hold the "Category Name" field with the mouse and drag it directly to the cell on the page. Release the mouse so that the cell contains a Dynamic text, the page effect is shown in Figure 11.
Figure 11
It’s just that this cell can only display one row now (you can check in the browser first to see if it displays like this), so how can we display all the field contents?
6. Select the table, then select the Server Behaviors tab in the Application panel on the right, press the plus button, and select Repeat Region. This way you can control how many records are displayed on one page. Here, because there are not many book categories, we select All Records (display all records) in the dialog box and display it without pagination, as shown in Figure 12.
Figure 12
7. Run pws, set the path, open this web page with a browser, and see if all the category names in the database are displayed on the screen, but you cannot click in yet. Okay, let's create the corresponding page for displaying books.
3. Create a page displayed by category query
1. Create a new dynamic web page and name it xianshi.asp.
2. Create a record set. Select the Bindings tab in the Application panel, press the plus button, select Recordset (Query), and the Recordset dialog box pops up. The settings inside are as shown in Figure 13. The name is Recordset2. Select tushu for the database table because the book information displayed on the web page is based on the previous query. Conditions are displayed, so it is necessary to set a restriction condition to select books that meet the conditions. So how is this condition transmitted and accepted? This requires the use of URL Parameter. You can use this parameter to pass the query conditions from the query web page, and then accept this parameter in the display web page to display matching records. The specific usage is as follows:
Figure 13 (1) First let us return to the query page chaxun.asp. Use the mouse to select the fields in the table, then select the Server Behaviors tab on the Application panel, press the plus button, and select Go To Detail Page. The Go To Detail Page dialog box will pop up. The specific settings are shown in Figure 14. The Detail Page is our display web page xianshi.asp. What is entered in the Pass URL Parameter text box is the parameter name to be passed to the detail page through the URL. For ease of understanding, we enter the "category name". This name can be displayed later. The parameter names set in the web page are the same. Recordset means which record set it is passed from. We choose Recordset1. Column means the source of the URL parameter value. It must be consistent with the query conditions on the query web page, so select "Category Name". The two options of Pass Existing Parameters are in It is related to the form, but the form is not used on this query page, so you can not select it. Click the OK button, and you can see that the field in the table has become a hypertext link containing dynamic content.
Figure 14 (2) OK, the URL Parameter has been set, now return to the displayed web page xianshi.asp to accept this parameter. Select Recordset (Query), the Recordset dialog box pops up, and set it in Filter as shown in Figure 13 above, which means: the query condition is that the field "category name" in the table tushu must be equal to the passed URL Parameter parameter "category name", so that the web page can be queried It is linked to the display of the web page.
(3) Click the test button to test. You can enter a category name, and dw will display the corresponding book records.
(4) Click the OK button to return to the page. The record set is now established.
3. Enter the static content in the web page, as shown in Figure 15. The "return" link is to the query web page chaxun.asp. Because some categories have many books, the display is set to paging.
Figure 15 4. Use the method introduced above to drag the fields of the record set to the corresponding positions on the page, as shown in Figure 16.
Figure 16 5. Select the second row in the table, click the Server Behaviors label in the Application panel, press the plus button, select Repeat Region, and the Repeat Region dialog box pops up. Because it is displayed in pages, I choose to display a few items at a time. Here I The input is 10, which means 10 records are displayed on each page. You can enter freely according to the situation, as shown in Figure 17. Click the OK button to return to the page.
Figure 17 6. Because it is displayed in pages and needs to be turned, how to achieve it in dw? It's very simple. You first select "Home", then click the Server Behaviors tab in the Application panel. Press the plus button. You can see a Recordset Paging option. Slide the mouse over this option to display the drop-down menu. The meaning of these menus. I think everyone should understand it, as shown in Figure 18. Select the first "Move To First Record", a dialog box will pop up, as shown in Figure 19, click the ok button to return to the page, so that the dynamic link of "Home Page" is ready, and the other "Previous Page" and "Next Page" ", "Last Page" and so on, and make dynamic links corresponding to them.
Figure 18Figure 19 7. So how does the user know that the record has reached the last one and should not scroll any further? Here, I solved it like this. If the record has reached the last one, the "next page" and "last page" will be automatically hidden on the page. Similarly, if the record has reached the first one, then the "first page" and "previous page" will be automatically hidden on the page. Page" is automatically hidden. The following is the specific implementation method:
(1) First select "Home", then click the Server Behaviors tab in the Application panel, press the plus button, and slide the mouse to the Show Region option to display the drop-down menu, as shown in Figure 20.
Figure 20 (2) Select "Show Region If Not First Record", which means that if it is not the first record, it will be displayed, and conversely, if it is the first record, it will not be displayed or hidden.
(3) Click the OK button directly on the pop-up dialog box to return to the page, so that the automatic hiding function of the "Home Page" is ready.
(4) In the same way, make several other automatic hiding functions. "Previous page" is the same as "Home", select "Show Region If Not First Record"; "next page" is the same as "Last page", select "Show Region If Not Last Record".
At this point, the page displayed by category query is finally completed. Let’s take a look at the specific effects. Run pws, use IE to open chaxun.asp, click on a category name, such as "New Drugs", IE will automatically display the books in this category, click on the "next page", "previous page" and other links to see Check whether IE will automatically turn pages. The specific effect is as shown in Figure 21 and 22.
Figure 21Figure 22 4. Create a web page for querying based on book titles
1. Create a new dynamic web page and name it chaxun1.asp.
2. Enter the statically displayed content on the web page, as shown in Figure 23. The "return" link is to the homepage index.htm. The red dotted line indicates that this is a form. The attribute settings of the form are as shown in Figure 24, which means post (pass) a form variable name. Go to the xianshi1.asp web page and execute this web page, so that the query web page and the displayed web page are linked through the variable name; the text box is named ts. Please remember this name, because this is the variable name to be passed through the form, and the following It is also used to display web pages.
Figure 23Figure 24 5. Create web pages displayed by book names
1. Create a new dynamic web page and name it xianshi1.asp.
2. Enter the statically displayed content on the web page, as shown in Figure 25, where the "return" link links to the query page chaxun1.htm, and the red dotted line also indicates that this is a form.
Figure 25 3. Create a record set. Select the Bindings tab in the Application panel, press the plus button, select Recordset (Query), and the Recordset dialog box pops up. The settings inside are as shown in Figure 26. The name is Recordset1, the database table selects tushu, and the Filter filter condition is set to the field in the table tushu. The "book title" must contain the passed Form Variable ts. This ts variable is the name of the text box in the query web page chaxun1.asp. Click the ok button to return to the page.
Figure 26 4. Drag the fields of the record set to the corresponding positions on the page.
5. Select the second row of the table, click the Server Behaviors tab in the Application panel, press the plus button, select Repeat Region, the Repeat Region dialog box will pop up, and set it to display all.
The final page effect is shown in Figure 27.
Figure 27 At this point, the page displayed by querying the book name is finally completed. Let’s take a look at the specific effects. Run pws, use IE to open chaxun1.asp, enter a name, such as "Quality Management", and IE will automatically display all books with "Quality Management" in the title. The specific effects are shown in Figures 28 and 29.
Figure 28Figure 29 The web page is finally finished and now everyone can run it completely. Tell your colleagues the IP address of your computer and open pws, so that your colleagues can query books through the query system at any time.
Click here to download the source code for this tutorial