How can I run a PHP function in an SQL statement to limit the query results? -Php Tutorial

Source: Internet
Author: User
How can I run a PHP function in an SQL statement to limit the query results? Please help. The purpose of the program is to execute the SQL statement first and then display the query results. However, if the query is performed and the result is displayed, the page is displayed. the code is as follows:
$ _ BCACHE-> cachesql ('shopsearch', 'Select I. itemid, m. mapapimark, m. itemid FROM '. DB: table ('shopitems '). 'I LEFT join '. DB: table ('shopessage ').'m ON I. itemid = m. itemid WHERE m. mapapimark! = "" ', 0, 1, $ tpp, 0, 'index', 'shop'); $ multipage = $ _ SBLOCK ['shopsearch _ multipage']; $ resultcount = $ _ SBLOCK ['shopsearch _ listcount']; foreach ($ _ SBLOCK ['shopsearch'] as $ value) {$ value = $ _ BCACHE-> getshopinfo ($ value ['itemid']); // merchant coordinate data processing $ value ['X _ preg1 '] = preg_replace ('/\ (/', '', $ value ['mapapimark']); // remove the brackets $ value ['storex'] = preg_replace ('/,(. *)/', '', $ value ['X _ preg1']); // remove the Y coordinate and the preceding comma, only the X coordinates $ value ['Y _ preg1 '] = preg_replace ('/\)/',', $ value ['mapapimark']) are retained; // remove the brackets $ value ['store'] = preg_replace ('/(. *),/', '', $ value ['Y _ preg1']); // remove the X coordinate and the following comma, retain only Y coordinates $ value ['juli'] = GetDistance ($ ClientY, $ ClientX, $ value ['store'], $ value ['storex'], 2 ); $ value ['juli'] = round ($ value ['juli'], 2); if ($ value ['juli'] <= $ Distance) {$ shoplist [] = $ value ;}}

This is a piece of code in DZ. I want to use WHERE m. mapapimark! = "" In this statement, call the calculation function GetDistance to calculate the queried mapapimark. if the calculated result is smaller than $ Distance, how can I write this data? Thank you.


Reply to discussion (solution)

If you are using an sqlite database, you can. Otherwise, you cannot.
You can write database functions or filter data in the result set.

It is recommended that the computing should be completed in the php code. if the database computing is complex, the performance will be affected.

Does the complexity of php computing not affect performance?

It is recommended that the computing should be completed in the php code. if the database computing is complex, the performance will be affected.

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.