jmac2501 Posted January 23, 2008 Share Posted January 23, 2008 This should be an easy fix but i can't find it. What this script is supost to do is, gather all the info for one section of my database called "reo". It then takes this data and places it into a website address so that my website scraper goes to the right place. The scraper then gathers its info and inserts it back into my database. But i keep getting "there was and error" repeated in the echo. So if someone could check it out for me i would be very thankful. <?php error_reporting(E_ALL ^ E_NOTICE); require_once("class_http.php"); $link = mysql_connect('mysql6.******', '******', '******') or die('Could not connect: ' . mysql_error()); mysql_select_db('dcremax') or die('Could not select database'); $result = mysql_query("SELECT * FROM listings"); while($row = mysql_fetch_array($result)) $num = @mysql_num_rows($result); mysql_close(); if($num>0){ $i=0; while ($i < $num) { $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(); } if($beg = strpos($h->body, "http://mlsmedia.metrolistmls.com/bigphoto/", 0 )) {$end = strpos($h->body, ".jpg", $beg ); $pic = substr($h->body, $beg, ($end + 4) - $beg ); echo("$pic"); echo("<br />"); } if($beg = strpos($h->body, "<td align=\"center\" class=\"PageTitle\" width=\"534\"><b> $", 0 )) {$end = strpos($h->body, "</b></td>", $beg ); $price = substr($h->body, $beg + 55, ($end - 55) - $beg ); echo("$price"); echo("<br />"); } if($beg = strpos($h->body, "<td class=\"PageTitle\" colspan=\"3\" align=\"center\"><b>", 0 )) {$end = strpos($h->body, ",", $beg ); $streetaddress = substr($h->body, $beg + 52, ($end - 52) - $beg ); echo("$streetaddress"); echo("<br />"); $str = '$streetaddress '; } if($beg = strpos($h->body, "<td class=\"PageTitle\" colspan=\"3\" align=\"center\"><b>", 0 )) {$end = strpos($h->body, "</b></td>", $beg ); $city = substr($h->body, $beg + 56 + strlen($str), ($end - 61 - strlen($str)) - $beg ); echo("$city"); echo("<br />"); } if($beg = strpos($h->body, "<td width=\"16%\" class=\"FormTitle\">Sq Ft</td> <td width=\"14%\">", 0 )) {$end = strpos($h->body, "</td> <td width=\"16%\"", $beg ); $squarefeet = substr($h->body, $beg + 76, ($end - 76) - $beg ); echo("$squarefeet"); echo("<br />"); } if($beg = strpos($h->body, "<td width=\"16%\" class=\"FormTitle\">Bedrooms</td>", 0 )) {$end = strpos($h->body, "</td> <td width=\"16%", $beg ); $bed = substr($h->body, $beg + 97, ($end - 97) - $beg ); echo("$bed"); echo("<br />"); } if($beg = strpos($h->body, "<td width=\"16%\" class=\"FormTitle\">Full Baths</td>", 0 )) {$end = strpos($h->body, "</td> <td width=\"16%", $beg ); $Fbath = substr($h->body, $beg + 81, ($end - 81) - $beg ); echo("$Fbath"); echo("<br />"); } if($beg = strpos($h->body, "<td width=\"16%\" class=\"FormTitle\">Half Baths</td>", 0 )) {$end = strpos($h->body, "</td> <td width=\"16%", $beg ); $Hbath = substr($h->body, $beg + 99, ($end - 99) - $beg ); echo("$Hbath"); echo("<br />"); } if($beg = strpos($h->body, "<td width=\"60\"><b>Agent</b></td>", 0 )) {$end = strpos($h->body, " ", $beg ); $agent = substr($h->body, $beg + 85, ($end - 85) - $beg ); if(trim($agent) == "Diane C Cox")$agent = "Diane Cox"; if(trim($agent) == "Lizette Gonzalez </td> </tr> </table> </td> </tr> <tr> <td height=\"17\" colspan=\"3\"> <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\"> <tr> <td width=\"60\"><b>Office</b></td> <td class=\"body14\"> <a href=\"../Offices/01rmxg08.cfm\" class=\"link2\"><b>RE/MAX Gold Sacramento</b></a>")$agent = "Lizette Gonzalez"; echo("$agent"); echo("<br />"); } if(trim($pic) == "")$pic = "../images/nophoto1b_small.jpg"; if(isset($price)) { $link = mysql_connect('mysql6.******.com', '*****', '******') or die('Could not connect: ' . mysql_error()); mysql_select_db('dcremax') or die('Could not select database'); $sql = "INSERT INTO $_POST[Listings] (`streetaddress`, `city`, `price`, `squarefeet`, `bed`, `Fbath`, `Hbath`, `reo`, `agent`, `pic`) VALUES ('$streetaddress','$city','$price','$squarefeet','$bed','$Fbath','$Hbath','$REO','$agent','$pic')"; echo("$sql"); mysql_query($sql); if(mysql_query($sql)) { echo "Success!"; } else{ echo(" FAILED TO INPUT DATA <p><a href=\"../Members/Error.htm\">CLICK HERE</a></p>"); } } else echo "there was and error"; } } ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 23, 2008 Share Posted January 23, 2008 man... its very hard to understand your code.. please indent your code properly it is very hard to know the logical arrangement of this code Quote Link to comment Share on other sites More sharing options...
jmac2501 Posted January 23, 2008 Author Share Posted January 23, 2008 im sorry. But i think the problem is somewhere when it trys to select the info from my database. because if i place the info it to the $reo part of this string if (!$h->fetch("http://metrolistmls.com/cgi-bin/GetOneR.cfm?County=SA&iRow=0&nJL=7&MLSNum=$reo")) Everything works fine. So im thinking its has to do with this part: <?php error_reporting(E_ALL ^ E_NOTICE); require_once("class_http.php"); $link = mysql_connect('mysql6.******', '******', '******') or die('Could not connect: ' . mysql_error()); mysql_select_db('dcremax') or die('Could not select database'); $result = mysql_query("SELECT * FROM listings"); while($row = mysql_fetch_array($result)) $num = @mysql_num_rows($result); mysql_close(); if($num>0){ $i=0; while ($i < $num) { $reo=mysql_result($result,$i,"reo"); Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 23, 2008 Share Posted January 23, 2008 error_reporting(E_ALL ^ E_NOTICE); require_once("class_http.php"); $link = mysql_connect('mysql6.******', '******', '******') or die('Could not connect: ' . mysql_error()); mysql_select_db('dcremax') or die('Could not select database'); $result = mysql_query("SELECT * FROM listings"); $num = @mysql_num_rows($result); if($num > 0){ while($row = mysql_fetch_array($result)){ eho $row[ filedname here]; } } mysql_close(); may be this is what you mean Quote Link to comment Share on other sites More sharing options...
jmac2501 Posted January 24, 2008 Author Share Posted January 24, 2008 Thanks that worked to echo the file name like i wanted but i still am not getting it to insert the "file name ($reo)" into the webaddress. Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 24, 2008 Share Posted January 24, 2008 what do you mean by insert the "file name ($reo)" into the webaddress can you explain a a bit more? Quote Link to comment Share on other sites More sharing options...
jmac2501 Posted January 24, 2008 Author Share Posted January 24, 2008 ok at this point echo $row[ filedname here]; the file name = reo. I need every number ( reo number) that is echo to be placed where the $reo is on this line if (!$h->fetch("http://metrolistmls.com/cgi-bin/GetOneR.cfm?County=SA&iRow=0&nJL=7&MLSNum=$reo")) but i don't think its working. once i can get it to place the reo number there the script should work. Sorry, i know its confusing. Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 24, 2008 Share Posted January 24, 2008 $reo = $row[ filedname here]; //your field name here is your fields in your tbls in your db! Quote Link to comment Share on other sites More sharing options...
jmac2501 Posted January 24, 2008 Author Share Posted January 24, 2008 and I also need it to repeat for all the inputs in that listing. for exp: in my database there is a listing called reo. in that listing there are meny diffrent # that i need to pull from my data base. Thats where this part comes in right? if($num>0){ $i=0; while ($i < $num) { ......script.... Quote Link to comment Share on other sites More sharing options...
jmac2501 Posted January 24, 2008 Author Share Posted January 24, 2008 $reo = $row[ filedname here]; //your field name here is your fields in your tbls in your db! yeah i know i put "reo" there. that is the field name. but it only echo's the first field instead of echoing all of them. Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 24, 2008 Share Posted January 24, 2008 while($row = mysql_fetch_array($result)){ $reo = $row[ filedname here]; <-------------this is the prob } note once the loop runs $reo will contain new value and the other value will be over written so if you need all the result you might need array or put that statement inside the loop Quote Link to comment Share on other sites More sharing options...
jmac2501 Posted January 24, 2008 Author Share Posted January 24, 2008 ok thanks i got that part working... but now i need to figure out why i am still getting "there was an error". If it was working right i should see sussfull and all the right things echoed... THanks for the help ill keep looking into it. Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 24, 2008 Share Posted January 24, 2008 glad it works but i dont wanna look into your codes, like i said indent your codes its pretty hard to know the error specially when the if's has the problem.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.