RE: [PHP-DB] Populate Array During Loop With in_array

From: Date: Thu, 06 Mar 2003 15:05:11 +0000
Subject: RE: [PHP-DB] Populate Array During Loop With in_array
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-26120@lists.php.net to get a copy of this message
> 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); > > You're resetting $i back to 0 for each row returned from the database. So if there are multiple rows (which you say there are) then the array entries will get overwritten each time... HTH Rich

« previous php.db (#26120) next »