Re: creating an array in a while loop

From: Date: Mon, 16 Oct 2000 17:11:34 +0000
Subject: Re: creating an array in a while loop
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-20431@lists.php.net to get a copy of this message
Hey Henti: > $select_array[]="$row["lan"]=>$row["name"]"; Associative arrays need to be outside a quoted string to work, so do this: $select_array[] = $row["lan"] . "=>" . $row["name"]; Anyway, your inital code should have worked just fine: > $result=mysql_query($query); > while ($row=mysql_fetch_array($result)){ > $key=$row["element1"]; > $value=$row["element2"]; > $endarray[$key]=$value; > } Though I would do it a little differently: $result=mysql_query($query); while ($row=mysql_fetch_array($result, MYSQL_ASSOC)){ $endarray[$row["element1"]]=$row["element2"]; } Enjoy, --Dan -- PHP scripts that make your job easier http://www.analysisandsolutions.com/code/ SQL Solution | Layout Solution | Form Solution T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

« previous php.general (#20431) next »