Re: Extracting values from an array (I think)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for your kind reply, John. I've not used the variable variable 
technique before but do recall reading about it in the PHP Bible. 

I'll give it a try.

David





John Krewson <krewsonj@xxxxxxxxxxxxxx>

11/24/2003 01:33 PM



 

To:
php-db@xxxxxxxxxxxxx
cc:





Subject:
Re:  Extracting values from an array (I think)



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

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux