I have the following script:
<?php
ini_set('max_execution_time', 0);
include("../includes/mysqli.php");
$pointsvar = 50000;
$inserts = 0;
$locationvar = 32000006;
while($locationvar <= 32000260){
while($pointsvar >= 20000){
$url = "http://185.112.249.77:9999/Api/Search?search=&level=0&min=1&max=50&points=$pointsvar&loc=$locationvar";
$jsondata = file_get_contents($url);
$data = json_decode($jsondata, true);
$in=$data['clanList'];
$results = $data['results']; //max is 64
$i = 0;
while($i + 1 <= $results){
$clanid = $in[$i]['id'];
$clanname = mysqli_real_escape_string($con,$in[$i]['name']);
$clanplayerCount = $in[$i]['playerCount'];
$clanwarswon = $in[$i]['warsWon'];
$clanwarslost = $in[$i]['warsLost'];
$clanwarstied = $in[$i]['warsTied'];
$clanLocation = mysqli_real_escape_string($con,$in[$i]['clanLocation']);
$clanlevel = $in[$i]['level'];
$score = $in[$i]['score'];
$sql = "INSERT INTO activeclans(id, name, location, playercount, clanlevel, warswon, warslost, warstied, score)
VALUES('$clanid', '$clanname', '$clanLocation', '$clanplayerCount', '$clanlevel', '$clanwarswon', '$clanwarslost', '$clanwarstied', $score)";
mysqli_query($con, $sql);
$i++;
$inserts++;
}
$pointsvar = $pointsvar-500;
sleep(1);
}
$locationvar++;
sleep(1);
}
echo "Inserted $inserts";
?>
When I run it I am expecting it to go through each location and in each location I expect it to -500 from the $pointsvar until it reaches 20000. It was working until I made it go through each location in a while loop and now it just outputs Inserted 0
I have increased the max_execution_time as it could possible take a looong time to run. This script will be run on a cron around every day or week.
The expected output would be Inserted and a very very very big number..
Thanks for any help you can provide :D
locationvarset manually... And I'm sure it is correct so I'm confused.while($locationvar <= 32000260){loop then the issue must be in that newly added code. Remove it and check the code still works, then add the location loop again carefully$pointsvarin the loop. So after the first iteration of the outer loop, thewhile ($pointsvar >= 20000)loop will exit immediately.forloops instead ofwhileloops, you're less likely to run into problems like that.