Hey all,

Nevermind this. I just solved it myself.
I found out it does not matter when you decalre a variable as global (other than I guess before you use it)
So I made my function this way.
function key_value ( $mysql ) {
if ( $sao_row = $mysql -> fetchRow() ) {
do {
global ${"$sao_row[0]"};
${"$sao_row[0]"} = $sao_row[1]; // Create a variablle to pull the radio variable name
} while ( $sao_row = $mysql -> fetchRow() );
}
}


and it works like a charm.

Phillip

At 02:14 AM 8/31/2003 -0700, you wrote:
Greetings People,

Now basically I am trying to set up an easy way to have key value pairs listed in a DB, and then be able to call the name of the key as a variable later in the code of the page and list the corresponding value in the DB. I am almost there. However I just need to figure out some scope issues with functions.
I want to create variables with names on the fly through a function and have them last beyond the life of the function.
However I do not want to have to declare each key/variable as a global variable in the function, will defeat the purpose of this.


I have the following DB table
sao_key                         sao_value
app_past_enroll                         1
something                                       0
something_else                          1
yet                                             1

I have the following function
function key_value ( $mysql ) {
if ( $sao_row = $mysql -> fetchRow() ) {
do {
${"$sao_row[0]"} = $sao_row[1]; // Create a variablle to pull the radio variable name
} while ( $sao_row = $mysql -> fetchRow() );
}
}


I have the following code
$sql = "SELECT sao_key, sao_value FROM staff_app_options
$sao = new MySQL ( $sql );      #       Create an object with the above query
key_value ( $sao );

echo 'Past Enrollment = ' . $app_past_enroll . NL;
echo 'something = ' . $something . NL;
echo 'something_else = ' . $something_else . NL;
echo 'yet = ' . $yet . NL;

So how do I get the script to read $app_past_enroll as a variable after it has been created by the function?

Thanks for your help.

Phillip

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

Blessings


Phillip

+++++++++++++++++++++++++++++++++++++++++++++++++++
IMPORTANT: This email message (including attachments, if any) is intended
for the use of the individual addressee(s) named above and may contain
information that is confidential, privileged or unsuitable for overly sensitive
persons with low self-esteem, no sense of humor or irrational religious
beliefs. If you are not the intended recipient, any dissemination, distribution
or copying of this email is not authorized (either explicitly or implicitly) and
constitutes an irritating social faux pas. Unless the word absquatulation
has been used in its correct context somewhere other than in this warning,
it does not have any legal or no grammatical use and may be ignored. No
animals were harmed in the transmission of this email, although the barking
dachshund next door is living on borrowed time, let me tell you. Those of
you with an overwhelming fear of the unknown will be gratified to learn that
there is no hidden message revealed by reading this warning backwards,
so just ignore that Alert Notice from Microsoft. However, by pouring a
complete circle of salt around yourself and your computer you can ensure
that no harm befalls you, your family or your pets. If you have received this
email in error, please add some nutmeg and egg whites, whisk and place
in a warm oven for 40 minutes.
+++++++++++++++++++++++++++++++++++++++++++++++++++


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



Reply via email to