only iterates last value in db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

only iterates last value in db

Post 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>();

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

how do i do that? :?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

In your while loop:

Code: Select all

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

//Blardiblarblar

smurf();
}
...
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

thats what i thought but it dosnt work :cry:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it doesn't appear you're looking at the results of the looped curl call...
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

what does it appear im looking at? or how do i make it so it looks at the looped curl call?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

analyzing $result would at least look at the data returned from curl..
Post Reply