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

使用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

对于我对这个主题缺乏知识的无知感到抱歉但我无法在任何地方找到答案 。 p>

所以我有这个MySQL表: p>

  Feed_ID Vehicle_ID FullRegistration颜色FuelType年里程体型门使模型变量EngineSize价格PreviousPrice Transmission PictureRefs  ServiceHistory PreviousOwners说明FourWheelDrive选项注释新的二手站点起源V5条件ExDemo特许经营批准的TradePrice TradePriceExtra ServiceHistoryText Cap_ID 
  code>  pre> 
 
 

如您所见,每列都包含车辆数据。 p>

我在前端使用PDO显示了数据库中的所有结果,所有数据都以类似于Ebay的列表样式显示。 p>

现在我需要 为了过滤这些结果,我注意到许多结果过滤系统都在使用JS。 p>

这里有一些例子所以y 你会更好地了解我在说什么: p>

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

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

正如您所见 过滤器正在使用JS但是我在理解JS如何过滤MySQL查询时遇到了问题? p>

我知道这个问题可能有点广泛,但有人可以告诉我一个JS的例子 可以像我演示的例子一样过滤PDO结果吗? p>

谢谢 p> div>

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.