Populate Array During Loop With in_array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Can somebody please tell me why the $displayThese variable in the code
snippet below only gets populated with the last value in the $newsList array
even when $newsList has more than one row of data?

		while($newsList = mysql_fetch_array($result_getNews)){
			if($convReadList != ""){
				for($i = 0; $i < $countNewsItems; $i++){
					if (!in_array($newsList[$i],
$convReadList)){
						//echo $newsList[$i]." was
found\n";
						$displayThese[$i] =
$newsList[$i];
					}
				}
			}
			else{
				echo "<p>readList is empty</p>";
			}
		}
		print_r($displayThese);

$result_getNews is a small associative array of news article IDs drawn from
a MySQL db query. I know it has more than one row because I can print_r it
and see the data in the array. Furthermore, the echo... line below, the loop
prints out the IDs I expect to see. However, when I attempt to put them into
the $displayThese array, I only get the last news article ID in the result
set.

If the my $result_getNews variable holds an associative array
([0]=>2,[1]=>4,[2]=>6) and $convReadList is ([0]=>4) then the following
output is produced:

2 was found6 was found

but print_r($displayThese) produces Array([0]=>6) which is the last result
in the $resultGetNews set.

I have echoed and print_r() -ed every single variable to check its contents
and they all contain exactly what I expect them too up until that last
print_r($displayThese).

Is this related to the way in_array works, to the way an associative array
works or am I not populating the $displayThese array properly? Or have I
just been staring at this same code for waaaaay too long and am missing
something obvious?

Help is appreciated.

Thanks,
Rich


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux