Loop issue
Posted: Wed Jun 06, 2007 4:10 pm
I am having a problem inside the while loop of the function "mysql_select_array" in the class shown later in the post. I can call "regex_html" like so with out a hitch, and gives me the array I want.
That little script does wonders for me, it gives me the very large array I wanted. The problem is when I do it inside this loop in "mysql_select_array" function. it returns:
Don't mind the connect(), database(), and close() inside the "mysql_select_array" function. I made those to ease my pain and suffering with mysql. this is a clip of what the sql returns:
So yes, the regex patter is the same as it was in the script to run this class as above, the links are virtually the same, but I"m not sure why i'm getting an empty array instead of a very large one when using the function "mysql_select_array". Appreciate any help 
Code: Select all
$link = "http://devdata.worldbank.org/external/CPProfile.asp?PTYPE=CP&CCODE=BEN";
$pattern = '#face="Verdana,Tahoma,Arial,Helvetica">([^<]*)#';
$mika = new gdp();
$mika->regex_html($link, $pattern);from the script:Array ( [0] => Array ( ) [1] => Array ( ) )
Code: Select all
$mika = new gdp();
$grr = "gdp";
$mika->mysql_select_array($grr);Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=AFG [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=AFG ) Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=ALB [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=ALB ) Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=DZA [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=DZA ) Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=ASM [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=ASM ) Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=ADO [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=ADO ) Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=AGO [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=AGO )
Code: Select all
class gdp extends databasing {
var $link;
var $regex_pattern;
var $regex_array;
//---------------------Set F(x)'s---------------//
function set_link($blink){
$this->link = $blink;
}
function set_regex_pattern($pattern){
$this->regex_pattern = $pattern;
}
function set_regex_array($list){
$this->regex_array = $list;
}
//-----------------------Get F(x)'s--------------//
function get_regex_array(){
return $this->regex_array;
}
function get_link(){
return $this->link;
}
function get_regex_pattern(){
return $this->regex_pattern;
}
//----------------------------------------other stuff
function regex_html($url,$pattern){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
// curl_setopt($ch, CURLOPTFOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$result = curl_exec($ch);
curl_close($ch);
//$pattern='!<option value="([^"]*)">([^<]*)</option>!';
preg_match_all($pattern,$result,$ground);
//$this->set_regex_array($ground);
$this->set_regex_array($ground);
print_r($this->regex_array);
}
function mysql_select_array($database){
$this->connect();
$this->database($database);
$sql_0= "SELECT country_link FROM country_html;";
$result =mysql_query($sql_0);
$i=1;
$pattern = '#face="Verdana,Tahoma,Arial,Helvetica">([^<]*)#';
$this->set_regex_pattern($pattern);
while($row = mysql_fetch_array($result)){
print "<html>";
$this->set_link($row[0]);
print "this is link number ".$i.": ".$this->get_link()."< br>";
print "this is the pattern: ".$pattern."<br>";
print "this is the result: ";
$this->regex_html($this->get_link(),$this->regex_pattern);
$i++;
print"<br>";
}
$this->close();
}
}