The realization of classification sort of PHP text database

Source: Internet
Author: User
Tags php and php programming server memory
In PHP programming, if you use a text database, you may have a headache for sorting problems. The following sunny little describes how to use PHP to combine JavaScript scripts to implement this functionality: The following figure, when the user clicks on the corresponding heading category, if the category is different from the original category, according to the corresponding category of the same ascending and descending order; When the click category is the same as the original category, it is arranged in the reverse order of the category. (That is, if you put the mouse in the "singer" title, you will be prompted "in [singer] [ascending order]". )
The format of the text database in the example is as follows: Each line of information is saved in one file, the file content format is "song name | singer | size". For example, the file "find a word instead of. txt" content is "find a word instead of | Timi Zhuo |48554", each file has only one row, and saved in the "Data" directory.
 
Sorting the idea is: will be sorted in the category of information read to [] array, to [] arrange, get a new array of subscript of the Index [], and then press the array of the subscript to read out the file.
 
Here we write this PHP file.
 
OK, our program has been written. The program read two times the file, which may be slower, of course, you can change the contents of the file into an array in the first reading, so that the second reading, but this need to occupy more server memory, for the sake of security to sacrifice a little speed.
 
Today, Xiao Yang not only introduces the sorting method of text database, but also introduces the programming method of PHP and JavaScript in detail, the special application of ternary operator, the display rule of status bar and the application of HTML element custom attribute. OK, run the php file just edited on the server (click here to download the demo file). The attentive reader will soon find out what is missing. Yes, it's a paging display! Unfortunately, limited to space, here is not introduced, you go to perfect it.

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.