I tested looping nested While statements so:
$count1 = 0;
while ($count1 < 3) {
$count1++;
$count2 = 0;
echo "count1: ".$count1."<br />";
while ($count2 < 3) {
$count2++;
echo "count2: ".$count2."<br />";
}
}
This works perfectly (looping three times each) with results:
count1: 1
count2: 1
count2: 2
count2: 3
count1: 2
count2: 1
count2: 2
count2: 3
count1: 3
count2: 1
count2: 2
count2: 3
Then I tried the same with a loop using mysql_fetch_assoc ($ContactsInterests is a two row associative array, and $LatestNews has 50 rows) i.e.
$CI_count = 0;
while ($CI_Row = mysql_fetch_assoc($ContactsInterests)) { //loop thru interests
$CI_count++;
$LN_count = 0;
echo "CI_count: ".$CI_count."<br />";
while ($LN_Row = mysql_fetch_assoc($LatestNews)) { //loop thru news
$LN_count++;
echo "LN_count: ".$LN_count."<br />";
}
}
The results are:
CI_count: 1
LN_count: 1
LN_count: 2
...
LN_count: 50
LN_count: 51
CI_count: 2
But where it the second iteration of LN_count? I don't understand why the LN_count didn't increment a second time.
Help appreciated.
$LN_Row
contains only the last value passed bymysql_fetch_assoc
... so it won't fill up the$LN_Row
unless you do something like this$LN_Row[] = mysql_fetch_assoc
– Dexter Huinda Jun 23 '12 at 19:49