Cool General page Display Control (ii) Add query control

Source: Internet
Author: User
Pagination | control | In the previous article, we analyzed a simple common paging code control.
But usually we use the query function in the paging ASP page, so how to "encapsulate" the query?
The Include method is also required.

We can think of the query as two parts,
1, input, that is, to receive the user input query string, we put it in the Query.inc
2, output, that is, according to the user input content constructs the query condition, we put it in the Query_result.inc

In this way, our thinking is very clear,
1, put the query_result.inc before the SQL statement, construct the query criteria, and then embed the query criteria in the SQL statement
2, place the query.inc on the ASP page (usually the same line as Navigator.inc).


In the next article, it's a little bit more complicated, so let's take a look at a demo database: MyTest

Table 1 tbluserinfo ' User Information table

Field flduserinfo_id ' User ID
Flduserinfo_username
Flduserinfo_nickname
Flduserinfo_password

Table 2 Tbladdressbook ' Address Book list

Field fldaddressbook_id
Fldaddressbook_classid ' category ID
Fldaddressbook_userid ' User ID
Fldaddressbook_nickname

Table 3 Tbladdressbook_class ' Address Book category table

Field fldaddressbook_class_id ' Category ID
Fldaddressbook_class_title ' For example: friends, customers, relatives, netizens
Fldaddressbook_class_explain ' category description

View Vwaddressbook

SELECT Tbladdressbook_class.fldaddressbook_class_title,
Tbladdressbook_class.fldaddressbook_class_explain,
tbladdressbook.fldaddressbook_id, Tbladdressbook.fldaddressbook_userid,
Tbladdressbook.fldaddressbook_classid, Tbladdressbook.fldaddressbook_nickname,
From Tbladdressbook INNER JOIN
Tbladdressbook_class on
Tbladdressbook.fldaddressbook_classid = tbladdressbook_class.fldaddressbook_class_id

[Note: I added the name of the table to each field, which is convenient for generating views and other hidden hassles.] After my long attempt, I found this method really good. Therefore, we recommend this method of naming. ]

When we query in Tbladdressbook, we use Flduserid to differentiate each user's address book content, so add the "flduserid=" & Session ("UserID") restrictions. Now we add this restriction to our SQL statement.


Please see sample2.asp



< a > ASP files that require paging

Sample2.asp

<%
' Get the full path of the current ASP page, the important skill
Thescript = Request.ServerVariables ("Script_name")
Myconnstr = "Driver={sql server};server=yourserver;uid=sa;pwd=;d atabase=mytest"
Thepagesize = 20 ' number of records displayed per page

'//////////////////////////////////////////////////////////
'
' Define table name
'
'//////////////////////////////////////////////////////////

Thetablename= "AddressBook"

'///////////////////////////



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.