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

From: Date: Thu, 06 Mar 2003 16:33:11 +0000
Subject: RE: [PHP-DB] Populate Array During Loop With in_array
Groups: php.db 
Request: Send a blank email to php-db+get-26125@lists.php.net to get a copy of this message
Rich, Thanks! You pointed me in the right direction and I now have the code working and returning the expected results. If anybody's interested, just post back to the list and I'll post the working code. Don't want to bog the list down if nobody cares. Rich > -----Original Message----- > From: Rich Gray [mailto:rich@f1central.net] > Sent: Thursday, March 06, 2003 10:05 AM > To: Hutchins, Richard; php-db@lists.php.net > Subject: RE: [PHP-DB] Populate Array During Loop With in_array > > > > 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 (#26125) next »