PHP public development Notes (7 ). PHP public development Notes (7) PHP public development Notes Series date: 2014.9.6 this diary was completed yesterday and was not written yesterday. main functions: fuzzy search and questions about PHP public development Notes (7)
PHP public development Notes Series
Date: 2014.9.6
This diary is made up of yesterday, and it was not written in time yesterday;
Main functions: Fuzzy search, Q & A system, and help system
Fixed: _ SESSION id
Verification mechanism adjusted
Note: mysql syntax problems, mysql fuzzy match, and PHP associated arrays seem to be calculated using count, the size of the original data will be twice the size (that is, the array contains only two data, count will get 4, which needs to be verified again. it seems that this problem occurs when foreach is used)
Learned: PHP array operations
Sort notes:
When I write this note, I am catching up with the function. so I simply remember a few pieces of work at that time. now the function is almost developed, so I will sort out the previous notes. At that time, it was easy to record the above statements.
I remember, on the way to work that day, my classmates told me that the desired function is to enter the name of a city to get information from the students in the city. In fact, this function is what I initially wanted to achieve with this public account, so that we can easily retrieve information. although at this stage, we may not have many people walking around, there is no such requirement. However, it cannot be ruled out by accident, so we have this idea.
Fuzzy search:
Fuzzy search is also based on database search. here we should get a keyword so that the service desk program can capture this keyword. I set it to view + XX to view the information, for example, if you want to view information about Guangzhou, you can reply to "view Guangzhou.
Specific implementation:
The first is keyword capture. This is similar to the one mentioned in Note 6. it is nothing more than using two string processing functions: strstr and str_replace to process user input; the key is how to deal with the retrieval of information from the database. at the beginning, my idea was to determine whether fuzzy search could be performed in the database. if not, I would first get all the information and then compare it;
Solution 1: fuzzy match of databases:
The information obtained from the Internet shows that fuzzy search is supported, but I tried it for several hours, but it is ineffective. I don't know if I have a wrong understanding of this fuzzy search, the syntax shown on the Internet is:
1,Select from xxx (data table name) where xxx (field) like xxx (which we want to search). This syntax can be used in a given data table, the field value is the information we want to search. However, we need to check multiple fields, that is, the data table contains province, city, and other fields. I need to perform fuzzy matching for these fields, so I started to check the information again;
2,Select from xxx where concat ('field _ A', 'Field _ B ', 'Field _ c') like xxx. here concat is equivalent to combining multiple fields, then perform fuzzy match. I followed this, but it still failed;
3,Select from xxx where xxx. colum_name like xxx, which is also the data to be viewed. The change is that the field name is changed to: data table. colum_name to match, but it is still useless;
The specific information I printed is not used. The information is retrieved using mysql_query. However, after this result is processed using mysql_fetch_assoc or mysql_fetch_array, no corresponding array is obtained. I do not know what the situation is; here, we should also note the fuzzy match information after like. according to the comments provided by netizens, if it is a Chinese character, it should be written in the format of % retrieval %, that is, both sides must have a percent sign.
Although I have not met my needs, I still feel that to operate the database well, I need to take a good look at the mysql Operation Manual.
Solution 2. obtain the information and then perform matching and comparison
This solution should be simple and easy to use, because I did this in my mobile game project. In fact, I also thought of this method when I first had the need for fuzzy search. However, I have considered that it takes time to obtain information from the database and access the database for retrieval. This may affect the performance, that's why I want to check whether there is a solution on the Internet. But it is counterproductive and does not meet the expectations. let's leave it for the future.
This solution is very simple. you only need to obtain all the information and then compare it. Here, an operation function of the php array is used to make the comparison very simple: in_array (); judge whether a value is in the array. Because the information we get from the database, php is processed into arrays. I retrieve the word Guangzhou, you only need to judge whether the word Guangzhou exists in these arrays, so it is relatively simple. The specific implementation is as follows:
Release + zqzK/release + CtLytMu52NPaxKO6/bzsy/release + Release/release/W + release + Release/release + CtPQwcvV4rj2z + Release/WwcujrNLyzqrO0s/ response + response/response + response/C0ruyvbvYuLTQxc + response/ptcTQxc + ioaO40L711eLR + response/qGjPGJyPgq + response/nS1LK7zOG + response/ authorization + iv8 + signature + qt6LOxLW11tC + zdPQvt/M5bXEy7XD98HLo6zO0r + 0tb3N + signature + tff1eldtnf2wcujuw.vcd4kpha + pgltzybzcm9" http://www.2cto.com/uploadfile/Collfiles/20140912/2014091209043527.png "Alt =" \ ">
Upload an array and then process it. then you can easily reply to the graphic link.
Here I will mention the link to jump after clicking:
Because I don't know how to get that link at all (I don't know it at all). later I thought it would be a file. This link is the storage address of this file. Then I wrote a file in php and put it in the Storage of SAE. I put this link and tested the effect.
When browsing the web page, I often see that the web page is mostly html, so I want to learn how to generate html files and how to generate html files on the Internet, web pages are generated online, word is saved as html, and dreamweaver is used for returning home. Later, html files were generated, but they did not match the needs of mobile browsing. it should be said that they are not like a web page at all. maybe I have a little bit of web page design basics, there are a lot of template materials on the Internet.
Later, I saw some documents from my classmates in the material library of the public platform, and thought, could you directly use the help document I used to process it, directly create a new clip with the help document information. In this case, add the help documents that have been written directly to the newly created materials, and save them to test the effect. The results are satisfactory, that is, the effect I want. it is like a webpage opened on a mobile phone. Because of my obsessive-compulsive disorder, I always had to adjust the format, so I had to sort it out until that day. it was Friday, and the house I rented was almost 8 o'clock in the evening, when I came back, I had to clean up the public platform, and then I was busy at around 12 o'clock. Although tired, I am very happy.
PHP notes:
1. I encountered a problem during the development on this day. $ _ SESSION encountered a problem: saved information, which is accessible to every user. When querying information on the internet at that time, to make the information obtained by each user inconsistent, you need to set the ID, that is, to use a unique user information to set the id, in this way, the information obtained by each user is inconsistent:
Session_id () uses this function to set the id
Because of the information received by the public account, there is a user who indicates the message to be sent. you can use this id to make the value unique, so I set the id based on the user information, but something went wrong later. I initially thought it was a problem with this mechanism and thought I was not using it properly. So adjusted the function call sequence:
Originally
Session_id ();
Session_start ();
If the call order is incorrect, I changed the order and the result is still incorrect. Later, I carefully read the set id and found that I wrote the user information wrong. The case was not clear, and it was really sloppy.
The user information obtained from the server is as follows:
$ PostObj-> FromUserName
I used $ postObj-> fromUserName
But I have never found out... Ah...
2. php array:
When using an associated array, if you use foreach for loop, the number of cycles will be twice the count size. This problem occurs when I perform fuzzy search. At that time, I did not use in_array for matching, but used a loop array for matching. The information I found on the internet is that the associated array uses foreach for matching, so that we can get the key value:
foreach ($array as $key => $value) { if($array[$key] == xxx) $res_array[] = $array[$key];}
When I did this, the number of cycles was twice the size of the array. I printed the key and showed that the associated key was printed, print the value key again. That is, the key value is printed for the first time, and the associated key is printed for the second time. the same element is printed twice. So when I make a match, I will get two identical arrays. I don't know where I am using it.
Tips (7) PHP public development Notes Series date: 2014.9.6 this diary is supplemented by yesterday, and was not written yesterday; main functions: Fuzzy search, question...