Re: Not Quite: how to build an array

From: Date: Sat, 23 Feb 2002 18:03:45 +0000
Subject: Re: Not Quite: how to build an array
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-85951@lists.php.net to get a copy of this message
On Saturday 23 February 2002 14:43, jtjohnston wrote: > OK. I use: > > while ($mydata = mysql_fetch_object($news)) > { > $authors = explode(";", $mydata->AS); > } > > Then why "Invalid argument supplied for foreach()" Have you checked that $authors is indeed an array? Try print_r($authors), if you see an Array printed then you're OK, anything else then $authors is not an array hence your foreach loop fails. Also what does a typical 'AS' field look like? > Am I indeed building an array as I go through my database? As it stands your code will only get the last set of $authors. Your while loop is not adding to $authors, it is replacing it each time through the loop. Thus you'll end up with whatever is in the last row of the results. As someone already suggested, you could use: array_push($authors, explode(";", $mydata->AS)); -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* It's not the men in my life, but the life in my men that counts. -- Mae West */

« previous php.general (#85951) next »