Reputation: 15
I would like to reset counter in the following loop. Have no idea how to do it
$j = 1;
while($row = mysqli_fetch_array($check)) {
$value = $row['tmpi'];
$calculate = mysqli_query($link,"SELECT * FROM tmpi_db WHERE tmpi_id = '".value."'");
$action = mysqli_num_rows($calculate);
if($j == $action) {
//RESET $j, $j must be one again, nothing is working I have tried $j = 1;
//It's keep incrementing 1,2,3,4,5,6,7.....
}
}
$j++
Please help
Upvotes: 0
Views: 2733
Reputation: 784
You can try this
if($j == $action) i{
//your code
$j=0;
} else {
$j++;
}
Upvotes: 0
Reputation: 4967
Something like this should work. Simply start at zero, increment it in beginning and reset the $j
if the action occurs, the next time it loops the $j
will increment again and be in zero configuration (i.e. contain value 1):
$j = 0;
while($row = mysqli_fetch_array($check))
{
$j++;
$value = $row['tmpi'];
$calculate = mysqli_query($link,"SELECT * FROM tmpi_db WHERE tmpi_id = '".value."'");
$action = mysqli_num_rows($calculate);
if($j == $action)
{
$j = 0;
}
}
Upvotes: 1
Reputation: 2011
Just move your $j++
in an else section eg
if($j == $action){
//stuff and reset
}else{
$j++;
}
Upvotes: 1