Re: create and read array

From: Date: Sat, 11 Sep 2004 18:43:23 +0000
Subject: Re: create and read array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-196408@lists.php.net to get a copy of this message
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/ "John Taylor-Johnston" <taylorjo@CollegeSherbrooke.qc.ca> wrote in message news:41427614.811184DC@CollegeSherbrooke.qc.ca... > Can someone help me, show me how to do this please? > > 1. How do I write $mydata->AUS and $mydata->id into an array? > > $authors = array(); > while ($mydata = mysql_fetch_object($news)) > { > # echo "$mydata->AUS, $mydata->id\n"; > ??? write to array > } > mysql_close($myconnection); > > 2. Then I need to create $SQL > > foreach ($authors as something) > { > $sql += "INSERT INTO newtable VALUES ($AUS, $id);\r\n"; > } > > I am reading > http://ca3.php.net/manual/en/language.types.array.php but don't really get it. > > Can I do $sql += "blah"; or do I have to write $sql = $sql + "blah";?

« previous php.general (#196408) next »