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],
                                                //echo $newsList[$i]." was
                                                $displayThese[$i] =
                                echo "<p>readList is empty</p>";

$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

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

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.


PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to