Extracting Data but want unique content on each page?

Discussion in 'PHP' started by scm22ri, Jun 28, 2012.

  1. #1
    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

     
    scm22ri, Jun 28, 2012 IP
  2. geforce

    geforce Active Member

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #2
    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
     
    geforce, Jul 1, 2012 IP
  3. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #3
    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.
     
    NetStar, Jul 1, 2012 IP