Dynamic from the database to extract data from the database in the PHP entry page

zhaozj2021-02-08  434

Shijiazhuang Teachers College Calculation Center Zhang Shi Mei

Summary: When making a dynamic web page with PHP, let PHP immediately remove the value of the relevant other fields from the database according to the value of a certain field entered on the current page, and is displayed to the current page according to the value of the user entered on the current page, and is a PHP program. Difficulties in development. This article describes how to combine two HTML embedded languages ​​PHP and JavaScript in detail to solve this difficult point.

Key words: PHP, dynamics, HTML.

The current website has developed from the previous form of the interactive information service to deliver dynamic information services. Web information service form can summarize two points: provide information to customers; record information submitted by customers. To provide these two services, the problem that needs to be resolved is: How to quickly let the user quickly extract the information he wants in a lot of information on his website, how to effectively record the information submitted by the user in order to find the user in the future. These issues can be solved by adding database support in the website.

Because PHP can provide good support for multiple databases, and PHP's script is directly embedded in the HTML document, it is very convenient to use. Therefore, PHP is one of the most popular SERVER-side embedded languages ​​on the Internet. In addition, compared to other Server-end scripts such as ASP, php free open source and provide cross-platform support, which makes it easily adapt to various heterogeneous network environments in today's network; allowing webpage manufacturers to be very fast Conveniently produce a powerful dynamic web page. However, since PHP is the server-side embedding, a more intuitive understanding is that the PHP statement is executed on the server, so it only receives and processes the content on the current page when submitted. And when you need, based on the value of a certain field entered on the customer's current page, PHP is powerful when it is quickly extracted. For example: To provide a "order contract" entry page, which contain some "supplier information" entry, and each supplier's details have been entered in advance in a "business" dictionary table, now asked When the customer selects a "supplier" on the current page, the customer is immediately extracted from the "Business" dictionary, such as "open bank, account number, address, phone", etc. to display the current page. For customers to use or modify them directly. This requirement is a light and easy thing to implement with visual programming languages ​​such as PB, VB, but PB, VB is not suitable for writing dynamic web pages; PHP is suitable for writing dynamic web pages, but because the server is embedded, it cannot be submitted in time The variable value on the front page, so there is a certain difficulty in achieving the above requirements. In the process of writing, I combine PHP with JavaScript to solve this difficult point.

We know that the embedded statement is equally embedded, but JavaScript is different from the PHP language. Because PHP is server-side embedding, JavaScript is a client embedding, which is executed on a customer's browser, which determines that JavaScript can get a variable value on the current page in time, but cannot directly operate directly on the server side. . Therefore, combine the two to make a powerful dynamic web page, which can be described as a bead joint. To describe convenience, the following is only taken from the Dictionary table as an example to explain the specific practice. When you need to take a plurality of fields, the method is similar, but it is carefully removed from the string using the JavaScript function.

1. Write a PHP function

The function of this function is to remove all qualified "supplier" from the "Business" dictionary table and store it into a string variable $ kHSZ.

Function KHQK_TQ ($ QUESTR) {

Global $ dbconn;

$ dbq_resl = Sybase_Query ($ questr, $ dbconn); // Send a query string for Sybase execution. $ dBQ_ROWS = Sybase_num_rows ($ dbq_resl); // Get the number of returns.

$ j = 0;

For ($ I = 0; $ I <$ dbq_rows; $ i ) {// Create loop, remove the desired fields in each row, and put it in the array $ k [].

$ K [] = Sybase_Result ($ DBQ_RESL, $ I, "KH_ID"); / / Remove the supplier number selected by the user.

$ add = Sybase_Result ($ DBQ_RESL, $ I, "Address"); // Remove the supplier address.

IF ($ add == ""):

$ K [] = "None";

Else:

$ K [] = Sybase_Result ($ DBQ_RESL, $ I, "Address");

Endif;

$ KHSZ = $ kHSZ. $ K [$ J]. "|". $ k [$ j 1]. "|"; // Connect each field value to "|" is separator, connected to variable $ kHSZ To form a long string.

$ J = $ J 2;

}

Return $ kHSZ;

}

2. Write a JavaScript function

The function of the function is to find the address of the supplier from the string according to the KH_ID value, embedded in the HTML file.