doumianfeng6979 2014-08-25 13:31
浏览 38
已采纳

使用JS / jQuery过滤PDO和MySQL查询

Sorry for my ignorance on the lack of knowledge I have on this subject however I cannot find an answer to my question anywhere.

So I have this MySQL table:

Feed_ID Vehicle_ID  FullRegistration    Colour  FuelType    Year    Mileage Bodytype    Doors   Make    Model   Variant EngineSize  Price   PreviousPrice   Transmission    PictureRefs ServiceHistory  PreviousOwners  Description FourWheelDrive  Options Comments    New Used    Site    Origin  V5  Condition   ExDemo  FranchiseApproved   TradePrice  TradePriceExtra ServiceHistoryText  Cap_ID

As you can see each column will contain vehicle data.

I have displayed all of the results in the database using PDO onto my front end, all data is displayed in a listing style similar to Ebay.

Now I need to filter these results however I have noticed that many result filter systems are using JS.

Here are some examples so you get a better idea of what I am talking about:

http://www.autotrader.co.uk/search/used/cars/

http://www.motors.co.uk/search/car/

As you can see all the filters are using JS however I am having a problem understanding how JS is filtering the MySQL query?

I know this question might be a little broad but can someone show me an example of how JS can filter PDO results just like the examples I have shown?

Thanks

  • 写回答

1条回答 默认 最新

  • duanang58939 2014-08-25 13:52
    关注

    The first one uses what I suspect to be a combined method of Javascript and a server-side language (it's hard to prove, because I can't see the server-side code involved). For simplicity, I'll assume this server-side language is PHP, though it could easily not be.

    Basically, all Javascript is doing on the first website is setting cookies and telling you to refresh the page. Once you refresh, PHP fetches the cookies that Javascript set and filters the results from the MySQL query based on those cookies.

    Now, the second one is actually filtering using Javascript, yet at the same time still using PHP (again, it could be any server-side language).

    This is a method called AJAX. It is a function built into Javascript which allows you to fetch another page from Javascript (aka. send and receive an HTTP request).

    The reason this is useful is because once you've changed an option on that page, Javascript can send an HTTP query using AJAX to something like "http://www.motors.co.uk/search/getcarinfo.php?transmission=manual", allowing PHP to fetch a new dataset from MySQL and return it to Javascript (this probably isn't the API entry point that they use, but it has to be somewhere in their Javascript).

    Once Javascript receives the response from that page (usually in JSON or XML form), it can modify HTML to update what's shown on the page.

    To answer your question directly, Javascript doesn't filter the data. MySQL filters the data based on a PHP query, which returns its response to the Javascript. Then, Javascript just puts it on the screen.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题