Re: create and read array

From: Date: Sun, 12 Sep 2004 16:17:17 +0000
Subject: Re: create and read array
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-196441@lists.php.net to get a copy of this message
Yeah, thanks. Good idea! It is good to code that: $authors = array(); while ($authors[] = mysql_fetch_assoc($news)); "Chris Martin" <chris@chriscodes.com> wrote in message news:ci0hu6$s1s$1@sea.gmane.org... > Alexander Kleshchevnikov wrote: > > Maybe you want this: > > > > while ($data = mysql_fetch_assoc($news)) { > > $sql += "INSERT INTO newtable VALUES ($data['AUS'], $data['id']);\r\n"; > > } > > > > If you nevertheless want save the data in array you can use a > > two-dimensional array $authors: > > > > $authors = array(); > > while ($data = mysql_fetch_assoc($news)) { > > $authors[] = array('AUS' => $data['AUS'], 'id' => > > $data[id]); > > } > > > > .. > > > > foreach ($author in $authors) { > > $sql += "INSERT INTO newtable VALUES ($author['AUS'], > > $author['id']);\r\n"; > > } > > > > -- > > Seigo > > www.geocities.com/seigo_ua/ > > > Just a note to help the learning process. Either mysql_fetch_assoc() and > mysql_fetch_array() will return your result in an array, so you don't > need to actually create one. > > -- > Chris Martin > Web Developer > Open Source & Web Standards Advocate > http://www.chriscodes.com/

« previous php.general (#196441) next »