Re: Extracting values from an array (I think)

From: Date: Mon, 24 Nov 2003 19:33:57 +0000
Subject: Re: Extracting values from an array (I think)
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-31719@lists.php.net to get a copy of this message
If you have to assign 24 unique variables rather than storing this data in an array, then you could apply some variable variable action. Here is a code sample that assumes you are looping through a result set from a database: query ="SELECT short_label FROM config ORDER BY meter_num"; $result= @MSSQL_QUERY($query) or die("Can't connect or something painfully obscure"); while($row = mysql_fetch_assoc($result)) { ${$short_label}=$row["short_label"]; } That will, I believe, give you a list of variables/values such as: $short_label_1 = short_label_1 $short_label_2 = short_label_2 You can also adjust the variable name to your liking, such as: ${$short_label._counterPerhaps}=$row["short_label"]; The above should be correct, but I do admit that I don't use this technique daily. To bad you cannot just throw your values into an associative array and pluck them when needed using $key => $value type of combinations. -John

« previous php.db (#31719) next »