Re: create and read array
| From: | M. Sokolewicz | Date: | Sat, 11 Sep 2004 18:58:20 +0000 |
| Subject: | Re: create and read array | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196409@lists.php.net to get a copy of this message | ||
Alexander Kleshchevnikov wrote:
Maybe you want this: while ($data = mysql_fetch_assoc($news)) {$sql += "INSERT INTO newtable VALUES ($data['AUS'], $data['id']);\r\n";} I seriously recommend using .= on strings instead of +=. += DOES work, that's true, but it's not INTENDED to be used on strings, rather to be used on arrays and numbers.
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 butdon't really get it.Can I do $sql += "blah"; or do I have to write $sql = $sql + "blah";?