Implement the background operation process of the MySQL bookshelf

Source: Internet
Author: User

The following articles mainly describe the background of the MySQL bookshelf, including the specific descriptions of its functions, the overall design of the MySQL database, and the actual operations of the MySQL database, the following articles mainly describe related content. I hope you will gain some benefits after browsing.

The Iterator of the Design Pattern writes a list class SortedArrayList. I don't know what the name should be. Who has experience hanging a MySQL bookshelf on the wall?

Function Description:

This is only a small module in the project. There are several novels and journals in the project. Each topic has books. In sns, when a user logs on to the project and sees a book, you can click "add to my bookshelf" and select "add to that bookshelf". Each bookshelf can hold 20 books, and each user can build up to 10 bookshelves. For books placed on the shelf, you can automatically drag them in my sorting, while in other update sorting, the order cannot be changed by the actual time,

Database Design:

The database is mainly used to store some information about books in the MySQL bookshelf, cover description addresses, and other important bookshelves category fields, which are implemented using a two-dimensional array). Each bookshelves can store books in 20 locations, you can set a field, which indicates the book id when you release the book. If you do not release the book, it is expressed as 0. You can use a two-dimensional array. The keys of the array are used to store the class of the bookshelves, the value is used to store information in this category,

Database Operations:

Database operation instructions the project is the same as the basic CURL operation. specifically in this project, it is added first. each user has a default data, which is the first array, you can change the name of the bookshelf to the key value of the array. For each array operation, when you add the bookshelf, move the location, and remove the shelf, when you add a book to a bookshelf, you also need to determine whether the bookshelf is full or not. In addition, the same book cannot be placed in a bookshelf more than twice.

For the entire field, a new array is created when the bookshelves category is added. The array in the initial field is an empty bookshelves. When a bookshelf is added, determine whether the maximum number of bookshelves is exceeded. You can control the number of bookshelves that can be created on the previous page according to the level.) create table bookshelf (uid int (11 ), shelf text); // create a bookshelf table

SQL code

$ Arr = array ('default data' => '0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0 '); // Insert the data of the default bookshelf, with a number and a key as the name of the bookshelf, value is the data location, which is empty by default,
 

 
 
  1. $ Text = serialize ($ arr); // serialize the Array
  2. Insert into bookshelf (uid shelf) values ("$ text", '$ uid'); // insert initialization data
  3. // Add a bookshelf. The 'shelf1' name must be unique.
  4. $ Shelfs = select shelf from bookshelf where uid = '$ uid'; // query the uid's bookshelf
  5. $ A = unserialize ($ shelfs); // deserialize the MySQL bookshelf to get the array,
  6. For (int I = 0; I <count ($ a); I ++) {// determines whether the bookshelf exists
  7. If ($ (a) [0] = shelf1 ){
  8. Return "this bookshelf already exists ";
  9. }
  10. Return true;
  11. }
  12. $ P = array ('shelf1' => '0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0 ');
  13. $ P = serialize ($ p); // Insert a new bookshelf
  14. Insert into bookshelf shelf values ('$ p') where uid =' $ uid ';
  15. // Add book1 'bid1' to shelf1.
  16. $ Shelfs1 = select shelf from bookshelf where uid = '$ uid ';//
  17. $ B = unserialize ($ shelfs1 );//
  18. For (int I = 0; I <count ($ B); I ++ ){
  19. If ($ B [I] [0] = '$ shelf1') {// obtain the MySQL bookshelf to be inserted.
  20. $ Pk = explode ('-', '$ B [I] [1]);
  21. For (int num = 1; num <count ($ pk [1]); num ++) {;/whether the bookshelf is full
  22. If ($ pk [1] [I] = 0 ){
  23. For (int k = 1; k <count ($ pk); k ++) {// determine whether there is a book to be inserted in the bookshelf
  24. If ($ pk [I] [1] = '$ bid1 '){
  25. Return 'this shelf already exists now ';
  26. } Else {// No book in the bookshelf can be inserted to the back by default
  27. If ($ pk [I] [1] = 0 ){
  28. $ Pk [I] [1] = $ bid1; // insert an array
  29. Return implode ("-", $ pk [I]); // return a string
  30. }
  31. } Else
  32. Return "this bookshelf is full ";
  33. }
  34. // Read the number of books in the list displayed when the bookshelves are added to an array
  35. $ Arr = new array ();
  36. $ Shlefs = select shelf from bookshelf where uid = '$ uid ';//
  37. $ Ss = unsersize ($ shelfs); // deserialize MySQL bookshelf Information
  38. For (int nn = 1; nn <count ($ ss); nn ++) {// name the bookshelf as a key
  39. $ Key = $ ss [I] [0];
  40. $ Value = 0;
  41. $ N = explode ("-", $ ss [I] [1]);
  42. For (int mm = 1; mm <count ($ n); mm ++) {// obtain the number of books in this bookshelf
  43. If ($ n [1]! = 0 ){
  44. $ Value ++;
  45. }
  46. $ Arr [0] = $ key;
  47. $ Arr [1] = $ value;
  48. }
  49. // Move bid2 from position 5 to position 8
  50. $ Startpos = 2;
  51. $ Endpos = 8;
  52. If ($ startpos <0 | $ startpos> 20 | $ endpos <0 | $ endpos> 20 | $ startpos = $ endpos) exit;
  53. $ Shelf =$ _ db-> fetch_first ("select * from 'sns _ shelf' where 'uid' = {$ uid }");
  54. $ Shelf select shelf from bookshelf wher uid = '$ uid ';
  55. $ Shelfs = unserisize ($ shelf );//
  56. Feach ($ shelfs as $ key, $ value ){
  57. $ Array = explode ("-", $ value );
  58. If ($ array [1] = 'id2') {find the MySQL bookshelf where bid2 is located
  59. If ($ sarry [1] [$ startpos] = 0) exit; // if there is no book in the starting position, do not exchange
  60. $ Temp = $ sarry [1] [$ endpos]; // Switch location
  61. $ Sarry [1] [$ endpos] = $ sarry [1] [$ startpos];
  62. $ Sarry [1] [$ startpos] = $ temp;
  63. $ Val = implode ("-", $ value [1]);
  64. $ Shelfs [1] = $ val;
  65. Serialize ($ shelfsl); // serialize shelf
  66. Update bookshelf set shelf = shelfs where uid = '$ uid ';
  67. Update
  68. }
  69. }


Dismounting books

 

Related Article

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.