Modernvox Posted January 8, 2010 Share Posted January 8, 2010 I have scraped data that needs to be dispersed INTO it's appropriate rows. The problem is the data pertains to specific States & Cities so i am wondering if I can do the following instead of creating hundreds of DB fields: $urls = array(); $insert = array(); if ($st == "AL") \\if State is Alabama { $urls = array("http://auburn.craigslist.org", "http://bham.craigslist.org"); //This will be popular cities in Alabama $insert= array("auburn", "bham"); // This will need to be Inserted INTO proper DB row to match city selected above // SO if user selects auburn listings I need to extract data from $insert('auburn')?? } else if ($st == "AK") { $urls= array("http://anchorage.craigslist.org"); } else if ($st == "AZ") { $urls = array("http://anchorage.craigslist.org"); } foreach ($urls as $url) { $html = file_get_contents("$url/muc/"); preg_match_all('/<a href="([^"]+)">([^<]+)<\/a><font size="-1">([^"]+)<\/font>/s', $html,$posts,PREG_SET_ORDER); //echo "<pre>";print_r($posts); foreach ($posts as $post) { $dbx= mysql_connect("", "", ""); if (!$dbx) { die('Could not connect: ' . mysql_error()); } //print $post[0]; //HTML $post[2] = str_ireplace($url,"",$post[2]); //remove domain echo "<a href=\"$url{$post[1]}\">{$post[2]}<font size=\"3\">{$post[3]}<br />"; print "<BR />\n"; } } mysql_SELECT_db("db_name", $dbx); mysql_Query("INSERT INTO $insert // Need to choose the State VALUES ("Value1', 'Value2', 'Value3')"); //Need to choose the city mysql_close($dbx); ?> Essentially what I am trying to accomplish is> avoid having to manually create a field for each city as there are hundreds. I would like to have the States set up and then just auto add the data INTO appropriate cities. Thank You. Link to comment https://forums.phpfreaks.com/topic/187735-can-i-use-a-variable-to-determine-which-db-row-data-is-entered/ Share on other sites More sharing options...
laffin Posted January 8, 2010 Share Posted January 8, 2010 why not just scrape the state/city pages as well? I notices that state pages all use http://geo.craigslist.org while cities have their own subdomain. Link to comment https://forums.phpfreaks.com/topic/187735-can-i-use-a-variable-to-determine-which-db-row-data-is-entered/#findComment-991288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.