I have the following loop/code:
$content = '';
$c = 0;
$s = 0;
$cat_count = $_POST['cats'];
$cat_count = $cat_count-1;
while ( $cat_count >= $c ) {
$settings_count = $_POST['count-'.$c.''];
$content .= '<pre>Category: '.$settings_count.'</pre>'; //just debugging
for ( $i = 0; $i <= $c; $i++ ) {
$content .= '<pre>Setting: '.$_POST['setting-'.$s.'-'.$i.''].'</pre>'; //just debugging
}
$c = $c+1;
$s = $s+1;
}
I'll try and explain it best I can...
$cat_count = $_POST['cats']; // $_POST['cats'] == 3
$cat_count = $cat_count-1; // $cat_count == 2 ( 0,1,2 ). Therefore, 3 categories.
Categories are set up in numeric form. So, 0 is the first category, 1 is second, 2 is third, etc.
$settings_count = $_POST['count-'.$c.'']; //first loop through: $_POST['count-0'] == 2
That gets the number of settings per category. So, there is 2 settings in the first category - 0.
for ( $i = 0; $i <= $c; $i++ ) {
$content .= '<pre>Setting: '.$_POST['setting-'.$s.'-'.$i.''].'</pre>'; //just debugging
}
Now, that will output the settings in the one category. So, it will loop 2 times, with the same category 0.
$s == 0 first run through - category 0 ( first category )
$i == 0 first run through - setting 0 ( first setting )
( $_POST['setting-0-0']; )
$i has to loop again, because there is 2 settings in the category 0.
$s == 0 second run through -category 0
$i == 1 second run through - setting 1 ( second setting ).
( $_POST['setting-0-1'] )
Now it should pop out of the FOR LOOP and go back to the while loop for the second category.
But, when it goes around the second time, i get:
$_POST['setting-1-1'], which gives me an error, because there's only one setting in the second category, so it should be $_POST['setting-1-0'].
So, i'm not sure why $i isn't being reset back to 0 once finished the first category run.
Sorry if it makes no sense, i figured i'd try and explain it for some help
I'm no good with loops._______________


.
.