PHP text database classification and sorting implementation. In PHP programming, if you use a text-based database, it may be a headache for its classification sorting problem. The following section describes how to use PHP and JavaScript scripts to implement this function. in PHP programming, if you use a text-type database, it may be a headache for sorting its categories. The following section describes how to use PHP and JavaScript scripts to implement this function. for example, when a user clicks the corresponding title category, if the category is different from the original category, the categories are sorted in ascending or descending order. when the click category is the same as the original category, the categories are sorted in reverse order. (That is, place the mouse in the title of "singer" during the holiday, and the prompt "sort by [singer] [ascending]" will be displayed ".)
In this example, the text database format is as follows: each line of information is saved under a file, and the file content format is "song name | artist | size ". For example, if you want to find a file replace. txt, you can find a word to replace. | Zhuo Yiting | 48554. each file has only one row and is saved in the "data" directory.
The idea of sorting by category is to read the information of the category to be sorted to the $ sort_array [] array and arrange $ sort_array, get the newly arranged array $ key_array [], and then read the file by pressing the array.
Below we will write this php file.
OK, our program has been written. The program reads the file twice, which may be slower. of course, you can store the file content in an array when you read the file for the first time, thus avoiding the second read, however, this requires a large amount of server memory, so we have to sacrifice a little speed for security.
Today, Xiaoyang not only introduced the classification and sorting methods of text databases, by the way, I also introduced in detail the programming methods combined with PHP and JavaScript, the special applications of ternary operators, the display rules of the status bar, and the application of custom attributes of HTML elements. Okay. run the compiled PHP file on the server. Careful readers will soon find out what is missing. By the way, it is displayed by page! Unfortunately, we will not describe it here. you should complete it yourself.
Bytes. The following section describes how to use PHP and JavaScript scripts to implement this function...