Hi Everyone, I'm extracting data (youtube video) from my mysql database but what I'm attempting to do is this. Instead of creating different mysql commands per page is it possible to one "generic" command that the page includes and knows what city I'm referring too in my page? Look at my below code to try and see what I'm referring to. Please look at both mysql commands. They are both different because they are on two separate pages. My question is, can I create a "generic" mysql commands that knows when its on the "nyc" page and extracts the NYC video and vice versa ...... Thanks! (Notice the mysql command) http://whatsmyowncarworth.com/auto/san-fran.php >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> (notice the mysql command) http://whatsmyowncarworth.com/auto/nyc.php
You could have something like the following: $city_name = $cities[str_replace('.php', '', $_SERVER['SCRIPT_FILENAME'])]; $query = "SELECT id,url,state,city FROM youtube WHERE city='{$city_name}'"; PHP: Then in your init.php file have an array of all your cities and page names. For example: $cities = array(); $cities['nyc'] = 'New York City'; $cities['san_fran'] = 'San Francisco'; PHP: Then whenever you need to change a city name or page name, simply edit your array in your init.php file. Hope this helps Thanks, Martin
Get a zip code database that will list all cities and states in the US. Use mod_rewrite for friendly URLs. Use the city name in the URL and have it rewrite to blah.php?city=$1 In blah.php (or whatever the name is) clean up the value of city by replacing dashes with spaces then use that as the mysql KEY to fetch the rest of the data. Pull the data from the table then use it throughout the page.