supermerc Posted January 8, 2009 Share Posted January 8, 2009 Hey, Im working on a script that uses cURL to login to a site and go to a page, and using limiters and delimiters i select what I want and then I tried to do if statements to make it not add items that were already added and it goes into an infinite loop for some reason, here is my code: <?php require("config.php"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://quiver.outwar.com/myaccount.php'); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, 'login_username=xxxxx&login_password=xxxxx'); curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $store = curl_exec ($ch); curl_setopt($ch, CURLOPT_URL, 'http://quiver.outwar.com/crew_actionlog.php?suid=55726&serverid=6'); $result1 = curl_exec($ch); echo strip_tags($result1); $query="select * from actionlog"; $result=mysql_query($query); echo mysql_num_rows($result); curl_close ($ch); $c=explode("\n",strip_tags($result1)); $s=false; $i=$r=0; $o=array(); foreach($c as $k=>$v){ $c[$k]=trim($c[$k]); if($c[$k]=='Dehitlist'||$c[$k]=='Next >>'){ $s=($c[$k]=='Dehitlist'); unset($c[$k]); continue; } if(empty($c[$k])||$s===false){ unset($c[$k]); continue; } if($i==3){ $i=0; $r++; } $o[$r][$i]=$c[$k]; $i++; } foreach($o as $k=>$v){ $v[3]=(eregi('Awarded',$v[1]))? 'Awarded' : 'Deposited'; echo $v[1]; preg_match("~(?:Deposited|Awarded)\s([^\(]+)\s\(([^\)]+)\)(?:\sto\s([^\b]+))?~",$v[1],$match); echo "<pre>"; print_r($match); echo "</pre>"; while($result = mysql_query($query)) { if($result['id'] == $match[2]) { } else { if ($v[3] == 'Awarded') { mysql_query("INSERT INTO `actionlog` (`name`,`item`,`date`,`action`,`itemid`) VALUES ('{$match[3]}','{$match[1]}','{$v[2]}','{$v[3]}','{$match[2]}')")or die ("MySQL Error". mysql_error()); } else if ($v[3] == 'Deposited') { mysql_query("INSERT INTO `actionlog` (`name`,`item`,`date`,`action`,`itemid`) VALUES ('{$v[0]}','{$match[1]}','{$v[2]}','{$v[3]}','{$match[2]}')") or die ("MySQL Error". mysql_error()); } else{} } } } ?> Link to comment https://forums.phpfreaks.com/topic/140052-infinite-loop-problem/ Share on other sites More sharing options...
Rushyo Posted January 8, 2009 Share Posted January 8, 2009 <?php while($result = mysql_query($query)) { ?> I believe that should be ==. This always returns true. Link to comment https://forums.phpfreaks.com/topic/140052-infinite-loop-problem/#findComment-732895 Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 <?php while($result = mysql_query($query)) { ?> I believe that should be ==. This always returns true. Almost buddy, keep the single equals but change mysql_query to mysql_fetch_assoc... $res = mysql_query($query); while($result = mysql_fetch_assoc($res)) { Should correct that issue. EDIT: Looking at your code, you define $result earlier on, so you probably do not need the extra mysql_query, but change that reference to be $res instead, so you do not have to change all instances of $result to be $row Link to comment https://forums.phpfreaks.com/topic/140052-infinite-loop-problem/#findComment-732906 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.