<?php
error_reporting(E_ALL ^ E_NOTICE);
// Put this up here
require_once("class_http.php");
// MySQL Connection
$link = mysql_connect('mysql6.******.com', '*****', '*****') || die('Could not connect: ' . mysql_error());
mysql_select_db('dcremax') || die('Could not select database');
// IMO, i only put the query in a variable if it's not going to be a constant
$result = mysql_query("SELECT * FROM Listings") || die(mysql_error());
$num = mysql_numrows($result);
for($i=0; $i<$num; $i++) {
$reo = mysql_result($result,$i,"reo");
$h = new http();
$h->dir = "/home/foo/bar/";
if( !$h->fetch("http://metrolistmls.com/cgi-bin/GetOneR.cfm?County=SA&iRow=0&nJL=7&MLSNum=".$reo) ) {
echo "<h2>There is a problem with the http request!</h2>";
echo $h->log;
exit();
}
// Grab all the info
if( preg_match_all("@http://mlsmedia\.metrolistmls\.com/bigphoto/(\d+)/(.*?)\.(jpg|png|jpeg|gif)@i", $h->body, $pictures) )
$pic = $pictures[0];
if( preg_match('@<td class="PageTitle" colspan="3" align="center"><b>(.*?)</b></td>@i', $h->body, $street) )
$street = $street[1];
if( preg_match('@<td align="center" class="PageTitle" width="534"><b> (\$\s*.*?)</b></td>@i', $h->body, $price) )
$price = $price[1];
// ... more and more ...
if(trim($pic) == "")
$pic = "../images/nophoto1b_small.jpg";
if( !empty(trim($price) ) {
$sql = sprintf("INSERT INTO listings ".
"(`streetaddress`, `city`, `price`, `squarefeet`, `bed`, `Fbath`, `Hbath`, `reo`, `agent`, `pic`) VALUES ".
"('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
mysql_real_escape_string($street),
mysql_real_escape_string($city),
mysql_real_escape_string($price),
mysql_real_escape_string($squarefeet),
mysql_real_escape_string($bed),
mysql_real_escape_string($fbath),
mysql_real_escape_string($hbath),
mysql_real_escape_string($reo),
mysql_real_escape_string($agent),
mysql_real_escape_string($pic));
mysql_query($sql) || die(mysql_error());
}
}
mysql_close($link);
?>
Finish the information extracting.