RE: Getting array values into a query

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

 



Try this:
I use it so that I can add variable names to a db table, then access them
throughout the script.

## Get the report_conf variables
   $sql = "SELECT *
           FROM report_conf";
    $prefs = get_rowset($conn_id,$sql);
      foreach($prefs as $pref){
        $foo = $pref['name'];
        $$foo = $pref['name_value'];
      }

The array you'd be interested in is $prefs, and it looks like this:
$key[0] = 'var1';
$value[0] = 'blue';
$key[1] = 'var2';
$value[1] = 'green';

After running the above, then
$var1 = 'blue';
$var2 = 'green';

I'm sure you'll need to tweak it a little, but the secret its the $$foo
(with two $ signs)
If $foo = 'aname'
then $$foo = $aname

The get_rowset is a function I've written to symplify my code, it returns
rows in an array from the DB


Gary Every
Sr. UNIX Administrator
Ingram Entertainment
(615) 287-4876
"Pay It Forward"
mailto:gary.every@ingramentertainment.com
http://accessingram.com


-----Original Message-----
From: Michael Conway [mailto:mconway3@cox.net]
Sent: Friday, February 07, 2003 4:47 PM
To: php-db@lists.php.net
Subject:  Getting array values into a query


I've been attempting to take the values from an array pulled from a
session to supply the variable in a WHERE clause. list() provides only
the first value as expected. implode() the last.  Any suggestions or
should I just load the values I want in the session through a query on
the previous script and call it directly to the function I want to use?

 

Michael Conway

mconway3@cox.net

(703) 968-8875

 


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

  Powered by Linux