Hi Everyone,
How do I extract specific data from a database without having to write hundreds of different mysql commands?
For example, if I want to extract then display only "car dealers" in New York City on my "New York City Page" --->> mydomain.com/new-york-city/used-cars. How would I make a script that will only "pull" or "extract" new york city car dealers without having to write different mysql commands?
Thanks
Extracting specific data from database?
Moderator: General Moderators
- Grizzzzzzzzzz
- Forum Contributor
- Posts: 125
- Joined: Wed Sep 02, 2009 8:51 am
Re: Extracting specific data from database?
use $_SERVER to obtain the current url (it'll either be PHP_SELF or REQUEST_URI, depending on how your pages are created)
parse that, and strip out the bit you want, and store it in a variable, then use that variable in your sql
considering the example of mydomain.com/new-york-city/used-cars, you'll probably want to futher format the string, i.e:
to ensure you're querying for 'new york city', not 'new-york-city' (depends how you've stored the name)
only additional things would be validation & any additional statements you want to query for
parse that, and strip out the bit you want, and store it in a variable, then use that variable in your sql
Code: Select all
$place_name = explode("/", $_SERVER['PHP_SELF']);
$sql = "SELECT * FROM table WHERE city = '$place_name[1]'";Code: Select all
$place_name = explode("/", $_SERVER['PHP_SELF']);
$formatted_place_name = str_replace("-", " ", $place_name[1]);
$sql = "SELECT * FROM table WHERE city = '$formatted_place_name'";only additional things would be validation & any additional statements you want to query for