I am using WordPress with JQuery to create a vehicle selection form.
Vehicle information is retrieved by JQuery Ajax calls to a PHP backend script. The PHP scripts query an SQLite database for vehicle information.
WordPress form -> JQuery get -> PHP script -> SQLite DB
I have three distinct queries that need to be executed:
- Vehicle makes available
- Vehicle models for a specific vehicle make
- Vehicle years for a specific vehicle make and model
I could create a custom PHP script that accepts a “query_type” parameter from the JQuery get call. The PHP script would then run the appropriate SQL query. That option sounds mediocre at best.
Should I create a custom PHP file for each of the three queries?
OR
Is there a neat PHP tool that will create something similar to .NET’s Service Endpoints?
Thanks Everyone!
Use JQuery to post the “type” of query you want to get. You should only need one PHP script, just let the PHP determine what type of data is being requested.
You might want to look into returning JSON data as it’s easier to deal with using JQuery: JQuery Docs – getJSON
As far as getting PHP to understand what’s being requested, use a query string in your URL: request.php?r=make, or request.php?m=datsun&r=model, or request.php?ma=datsun&mo=280zx&r=year
Then in PHP: