PHP micro-Credit Public development Note (vii) _php tutorial

Source: Internet
Author: User

PHP Public Development Notes (vii)


PHP Public Development Note series
Date: 2014.9.6

This diary is to fill yesterday, yesterday did not have time to write;

Main functions: Fuzzy search, question and answer system, help system
Fixed: _session ID
Adjusted the validation mechanism

Note: MySQL syntax problem, MySQL fuzzy matching, php associative array as if the size of the original data is twice times larger (that is, there are only two data in the array, Count will get 4, this need to re-verify, It seems that the problem is with the use of foreach)

Learned: operation of arrays in PHP

2014.9.10 Finishing Notes:
Write this note when, in the rush function, so that is simple to write a few pen at the time of the work content, now the function developed almost, to organize the previous notes. At that time, it was very simple to record the above sentence.
I remember, on the way to work that day, classmates told me that the function of hope is: Enter the name of a city, you can get information about the students in this city. In fact, this function is what I originally wanted to get the public number to achieve the function, so that it is very convenient to carry out information retrieval, although we may not have many people moving around at this stage, there is no need for that. But not by chance, so there is this idea.

Fuzzy Search:
Fuzzy Search, the word is also based on database retrieval, here should get a keyword, so that the Help desk program can capture this keyword, I set to view +xx to view information, such as to view the information in Guangzhou, then reply to "view Guangzhou" can.
Specific implementation:
The first is the keyword capture, this is similar to note six, it is nothing more than two string processing function: Strstr,str_replace processing user input information, the key is how to handle the retrieval of information from the database, at first my idea is to do in the database to do fuzzy retrieval, If it doesn't work, get all the information first and then compare it.
scenario One, the fuzzy match about the database:
The information from the online view is to support fuzzy search, but I tried for several hours, is no effect, do not know is not my understanding of this fuzzy search error, the online check to see the syntax is:
1.Select from XXX (data table name) where xxx (field) like XXX (we want to retrieve), the user gives the introduction is that this syntax can be retrieved from the given data table, the corresponding field value for the information we are looking for. But what we want to do here is a multi-field view, that is, the data table has provinces, cities and other field information, I need to do these fields fuzzy matching, so began to consult the data;
2.Select from the xxx where concat (' field_a ', ' field_b ', ' Field_c ') like XXX, here concat equivalent is to combine multiple fields, and then to do fuzzy matching, I follow this came, but still no success;
3.Select from xxx where xxx.colum_name like xxx, this is also the data that is consulted, the change is that the field name is changed to: Data table. Colum_name so to match, but still no use;
The specific is not used according to my printed information is, with mysql_query retrieved information, but this result with MYSQL_FETCH_ASSOC or mysql_fetch_array after processing, and did not get the corresponding array, do not know what the situation Here also to note is: Like after the fuzzy matching information, according to the comments provided by netizens, if it is Chinese characters need to write% to retrieve the format, that is, both sides must have a percent semicolon.
Although not to meet my needs here, but still feel that to be able to operate the database well, then you need to take a good look at the MySQL operating manual.
scenario Two, get the information to match the comparison
This program should be said to be very simple and easy, because I do the hands of the project is to deal with this, in fact, I initially have a vague search for this demand, but also think of this method. But I think, first of all from the database to get the information needed to access the database retrieval, and then to do the comparison and take the time, this may affect the performance, so I think in the online query whether there is a solution. But it backfired, did not achieve the desired, this is left to see later.

The solution is simple, just get all the information first and then compare it to the next. Here we use an operation function of the PHP array to make the comparison very simple: In_array (); Determine whether a value is in an array. Because we get the information from the database, PHP is processed into an array of, I search the word guangzhou, just need to determine whether in these arrays in Guangzhou this word can be, so relatively simple. Concrete implementation I do this:

vcv509c1xndfz6kjrmi7uvprrbu31ek49rb+zqzk/ Dfpo6zdv7to0a27t7xdtb3su7j2yv3x6ddfz6kjrmi7uvpipbj6ztldx9kqvozl97xejimymdu0mdvipbbuscijrmalxes1vchlvs29q9xiupbk /dfpt8w1vc7sw8e1xl3hufvk/dfp1tdipaosylu689tauvpd5rxestnx99bq1/a94bn7tkba7b7nv8ns1mhloam8yni+ctlytmu52npaxko6/ bzsy/fv4rj2uabe3lxjvs3v4th5yrxp1shloam8yni+cjxicj4kphn0cm9uzz7oyrtwz7xns6o6pc9zdhjvbmc+ pgjypgru2rm5y7zeo7r9vozl97xeyrg68qosztlsss/ro6zkx7fxxnzfqrj2uabe3mc0so/w+ s2s0ae72nlku9js5ltz0ae1xlarzveho9pqwcvv4rj2z+u3qnauuvojrm7subnlvmhl0ru49r3q1/ boyrtwtcs5pstco6y8tnpdu6e72li0zsq08kosz7xns77nt7w72nk7upboysziymptw7unykw72ltwoapv4tcpzsrm4ra8yse52npatpprp8n6u +61xkosyofrp7rf1q7a4lxeoam8yni+ctpqwcvv4rj2z+u3qnauuvojrlhjv6rkvnffytbktc/wwcujrnlyzqro0s/ rtb278tdt0ts689xiupa5pstcu+ht0mcp1bmjrmv50tto0tlu0ru49sdgwltktc/wo6zo0rpg1q7oqs7s1ek49s+1zbo1xnk7upbeo7/ po6yx49pazbpsu7ncwo2hozxicj4kvt/ m5bxeyrxp1rrcvpk1paosvs3kx9ta08o7p7vyulshsm7ktpchsbxeyrg68qos08mkx1nfu1njt068x8k80rvpwtpdu6e/qsb0wcvoyrtwxko/ 6aosylu689pdu6e1xm/c0ruyvbvyultqxc+ivs3kx7vytpde2sjdwcujrlvytpcyu7ncs8m5psqnsny2vmfls/219crfu0vtu0lptrny09rtw7unv6rg9m7ktpdeo7/ptctqxc+ioao40l711elr+ cq1z9a1w9pqteo88rwltnaxqaosuf65/qgjpgjypgq+38zlyrxp1rrcvpk1paosvli69co709df9rw9uty087xezsrm4qosy/ns1lk7zog+ 38zlyrxp1shloam8yni+cjxicj4kphn0cm9uzz6w79b6z7xns6o6pc9zdhjvbmc+pgjypgo8cd6w79b6z7xns87stcs5uc/ Rysejrmzhuann5txiupa5q9bausw1xl3ms8yjrlywvpk1pbxeupzqwsjv1r65pstcoapp67w90qrfqtxiw7s24kosxmfdtntzu9i4tm7esb7qxc +iv8+2ql7nsrvmq7rdwcujrmv50ts+zddo0qq72li0zbzoxmg0vdpby6gjzbzoxmg0vdo1xlvyultu2rnzt721xl+qt6loxlw11tc+zdpqvt/ m5bxey7xd98hlo6zo0r+0tb3n+nprtcs3vbeoo6y9q8th0ru087sueg1stk631r3iv6ratlsmwo2jrm7s0rk4+ Tff1eldtnf2wcujujwvcd4kpha+pgltzybzcmm9 "Http://www.2cto.com/uploadfile/Collfiles/20140912/2014091209043527.png "alt=" \ ">


Pass over an array, and then do the processing, you can easily reply to the text link.
Let's mention the link to jump after clicking on it:
Because I do not know how to get the link (a little concept), and then think of it should be a file, this link is the file's storage address. Then I just write a file in PHP, put it in the SAE storage, put the link here, test the effect is like this.
Often browse the Web page, and see the page is more HTML, so how to generate HTML files, in the online search data HTML file How to generate, but also the Web page generated, and Word saved as HTML, and then go home again with Dreamweaver. Later the HTML file is generated, but there is no good match the needs of mobile browsing, it should be said that it is not like a Web page, maybe I have a little bit of web Design Foundation should be able to have a lot of template material on the web.
Later, I had no intention to see my classmates in the library of the public platform to do some of the documents, I thought, can I use the Help document also use this library to process, directly create a new material, the content is to help the document information. Come on, add the Help document that was written directly to my newly created footage, and then save the re-test effect. The result is satisfied, is I want the effect, this just like the mobile phone opens the webpage. Because a little obsessive-compulsive disorder, always want to adjust the format of what, so busy to 12 o'clock in the morning before finishing, the day is Friday, back to rent the house is almost eight o'clock at night, back after a bit of tidying up the public platform, and then busy to 12 o'clock around. Although tired, but very happy.

PHP Note:
1, the development of the day encountered a problem, $_session problems: Save the information, each user can be accessed. At that time, in the online search for information, to make each user get inconsistent information, need to set the ID to achieve, even with a unique user information to set the ID, so that each user can be assured that the information is inconsistent:
SESSION_ID () Use this function to set the ID
Because of the information received by the public, there is a message that is sent to the user, you can use this as the ID to make the value unique, so I was the user's information to set the ID, but later problems. At first I thought it was the problem of this mechanism and thought I was using it improperly. So we have adjusted the order of the function calls:
was originally
session_id ();
Session_Start ();
The order of such calls, I think is not this order, I changed, the result is still wrong. Later, I seriously looked under the set of this ID, only to find that I wrote the user information is wrong, the case is not clear, really sloppy killed people.
The user information obtained from the server is this:
$POSTOBJ->fromusername
And I used it $postObj->fromusername.
And I have never found ... Ah ...
2. An array of PHP:
When using an associative array, if you use foreach to loop, the number of loops will be twice times the count size. This is the problem I encountered when I was doing fuzzy search. At that time I did not use the In_array to do the match, but used the loop array to do the matching, the data found on the Internet is that the associative array uses foreach to do the matching, so that you can also 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 times the size of the array, and I printed this key, showing that both the associated key was printed out and the value keys were printed out. That is, the first print is the value key, the second time to print the corresponding associated key, the same element will be printed two times. So when I make a match, I get two of the same array. I don't know if it's where I used the problem.

http://www.bkjia.com/PHPjc/879184.html www.bkjia.com true http://www.bkjia.com/PHPjc/879184.html techarticle PHP Public Development Note (vii) PHP Public Development Note Series Date: 2014.9.6 This diary is to fill yesterday, yesterday did not have time to write; main functions: Fuzzy search, ask ...

  • 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.