Page 1 of 1

only iterates last value in db

Posted: Thu Oct 13, 2005 3:02 pm
by SidewinderX
i have a database with 20 id numbers, i wanted to design a script so it grabs the id from the database uses it in a URL, then the script parses infromation from that URL and uploads the parsed info into another table and reiterate that for each id in the database. however the script iterates 20 times using the same id number (the last id number in the database). so after the script runs the table has 20 of the same pieces of information in it.

what am i doing wrong?

Code: Select all

<?
function <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>() {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://nw4.novaworld.net/NWStats.dll');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies');
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
}
function getbannedcookie($file) {
$dbhost = "localhost";
$dbuname = "";
$dbpass = "";
$dbname = "";
$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname, $db);
$q = "SELECT * FROM chid";
$result3 = mysql_query($q) or die ('Something is wrong with query: ' . $q . '<br>'. mysql_error());
while ($row = mysql_fetch_assoc($result3))
{
$chid = $row['chid'];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://nw4.novaworld.net/NWStats.dll?success=bhd_6_stat.htm&failure=bhd_6_main.htm&relay=bhd_6_relay.htm&msgbase=bhd_6_msg.htm&nodb=bhd_6_nodb.htm&statpage=bhd_6_stat.htm&pfid=26&statslot=0&action=stats&showchid=' . $chid . '');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $result = curl_exec($ch);
        curl_close($ch);

preg_match('/cid=(.*?), chid=(.*?), charactername="(.*?)" pcid="(.*?)"/', $file, $matches);

$chid1 = $matches[2];
$cid = $matches[1];
$name = $matches[3];
$pcid = $matches[4];
$result2 = mysql_query("INSERT INTO pcid SET chid='$chid1', cid='$cid', name='$name', pcid='$pcid'", $db) or die("Error: ".mysql_error());
}

}
getbannedcookie(<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>());
<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>();

?>

Posted: Thu Oct 13, 2005 8:17 pm
by feyd
<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>() should be called on each iteration of the query results

Posted: Fri Oct 14, 2005 2:42 pm
by SidewinderX
how do i do that? :?

Posted: Fri Oct 14, 2005 3:07 pm
by foobar
In your while loop:

Code: Select all

...
while ($row = mysql_fetch_assoc($result3))
{

//Blardiblarblar

smurf();
}
...

Posted: Fri Oct 14, 2005 4:05 pm
by SidewinderX
thats what i thought but it dosnt work :cry:

Posted: Fri Oct 14, 2005 4:10 pm
by feyd
it doesn't appear you're looking at the results of the looped curl call...

Posted: Sat Oct 15, 2005 10:33 am
by SidewinderX
what does it appear im looking at? or how do i make it so it looks at the looped curl call?

Posted: Sat Oct 15, 2005 10:39 am
by feyd
analyzing $result would at least look at the data returned from curl..