Implementation of classification and sorting of PHP text-based database _php tutorial

Source: Internet
Author: User
Tags php programming server memory
In PHP programming, if you use a text-based database, you might get a headache for sorting problems. The following Yang small describes how to use PHP in conjunction with JavaScript script to achieve this function: if the user clicks the corresponding title category, if the category is different from the original category, the corresponding category of the same ascending and descending order, when the click category is the same as the original category, then the same category in the reverse order. (That is, leave the mouse in the "singers" heading, and you will be prompted to "sort by [singers] [ascending]". )
 
In the example text database format is: Each line of information is saved in a file, the file content format is "song name | singer | size". For example, the file "find a word instead of. txt" is "find a word instead of | Timi Zhuo |48554", each file has only one row and is saved in the "Data" directory.
The idea of sorting is: Reading the information of the category to be sorted into the $sort_array[] array, arranging the $sort_array[], getting the array of the new arranged subscript $key_array[], and then reading the file in sequence by the subscript array.
Below we write this PHP file.
  
OK, our program has been written. The program read the file two times, this may be slower, of course, you can change the first time to read the contents of the file stored in an array, so as to avoid the second reading, but this requires more server memory, for security had to sacrifice a little speed.
Today Xiao Yang not only introduced the text database classification method, but also introduced in detail the combination of PHP and JavaScript programming method, the special application of ternary operators, the display of the status bar and the application of HTML element custom attributes. OK, run the PHP file you just compiled on the server to see. The attentive reader will soon find out what is missing. Yes, it is paginated display! Unfortunately, confined to space, here is not introduced, you go to improve it.

http://www.bkjia.com/PHPjc/532277.html www.bkjia.com true http://www.bkjia.com/PHPjc/532277.html techarticle in PHP programming, if you use a text-based database, you might get a headache for sorting problems. The following Yang small describes how to use PHP with JavaScript script 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.