PHP text database classification and sorting implementation

Source: Internet
Author: User
In PHP programming, if you use a text database, you may feel a headache for its classification and sorting titles. The following section describes how to use PHP and JavaScript scripts to implement this function: for example, when a user clicks the corresponding title type, if you use a text database in PHP programming, it may be a headache for sorting titles by category. The following section describes how to use PHP and JavaScript scripts to implement this function. for example, if a user clicks the corresponding title category, if the category is different from the original category, sort by the ascending or descending order of the corresponding category; when the click category is different from the original category, the order is in the reverse order of the category and the original category. (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 structure is as follows: each line of information is kept under a file, and the file content structure is "song name | singer | 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 stored in the "data" directory.

The idea of sorting by category is to read the information of the category to be sorted to the [] array and arrange [] to get the newly arranged array of the lower mark [], then, read the file in sequence by pressing the array of the mark.

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 bit of speed for the sake of security.

Today, Xiaoyang not only introduced the classification and sorting methods of the text database, by the way, PHP and JavaScript programming methods, special use of ternary operators, display rules of the status bar, and use of custom attributes of HTML elements are also introduced. Now, run the compiled PHP file on the server (Click here to download the demo file ). Careful readers will soon find out what is missing. By the way, it is displayed by page! Sorry, due to space limitations, we will not be able to accommodate it here. you should improve it yourself.

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.