PHP counter loop not working
I have the following code which should be inserting into the database x amount of times depending on the value given $row['max'] however only 1 is being inserted. Can someone please show me the error of my ways! Thanks.
$query = "SELECT * FROM challenges WHERE rate='fixed开发者_开发技巧'";
$query_result = mysql_query($query);
while ($row = mysql_fetch_array($query_result)) {
$spawn_time = preg_split('/,/', $row['time']);
$spawn_time_results = count($spawn_time);
$limitno = $row['max'];
$spawn_counter = 0;
while ($spawn_counter <= $spawn_time_results) {
if ($spawn_time[$spawn_counter] == date("i")) {
$time = time();
$insert_instance = "INSERT INTO instances (id,defeated,time)
VALUES ('{$row['id']}',0,{$time})";
$insert_result = mysql_query($insert_instance);
}
$spawn_counter++;
}
}
You never actually use $limitno, so it has no effect...
PS: please use explode instead of preg_split and for instead of this while loop.
Maybe it should be
$insert_instance="INSERT INTO instances (id,defeated,time)
VALUES ({$row['id']},0,{$time})";
精彩评论