PHP text database classification and sorting implementation _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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...

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.