开发者

checking cities against another database with states

I'm parsing an XML data feeds into a database, the feeds don't always have states listed in them and sometimes when they do, they are wrong. 开发者_JAVA技巧 I loaded up another table with what appears to be a fairly extensive list of all states/cities.

What I'm trying to achieve is to take my XML feed and while importing, reference that against the database of cities and pull the correct state. There are small variables such as "nationwide", "national" or "anywhere usa" which should theoretically be excluded. Also in events where the same city name is located in more than 1 state, I think my best bet is to add that to all associated states. For instance: Akron is in NY, Ohio, Colorado, so a feed with those variables would be added to all.

This sounds like a lot, but I really dont know if this just sounds complicated from my explanation or it really is.

Thanks in advance! EDIT:

I understand that I need to pull from my location database

'SELECT statename FROM statecities WHERE city = $city'

later

'UPDATE catalog SET statelong = $statename WHERE city = $city'

what i'm not sure about is how to do the following: create a loop that would check each $city from the file i'm parsing $product['city'] against each $city in the the table "statecities" and return $statename to be inserted into table "catalog".

My current code is:

foreach($arrXml['product'] as $product) {
foreach($product as $key => $value) {   
       if (@get_magic_quotes_gpc()) {
        $product[$key] = stripslashes($value); 
    }

    $product[$key] = mysql_real_escape_string($value);   
}    

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜