[Phplib-users] making proper use of f($field)
Brought to you by:
nhruby,
richardarcher
|
From: w.d. k. <fe...@fe...> - 2001-09-06 04:05:35
|
Greetings and Salutations All,
I'm having a bit of trouble using the f($field) method provided by the
DB_Sql class and have only you to turn to.
Within setup.inc, I'm attempting to load an array with user data pulled
from a database and make that array globally accessible for further
manipulation. Previous tests prove that $userdata["user_id"] is both
set and global. Also, I have determined that the query($query) method
is functioning as I would expect.
Several websites suggested calling next_record() before attempting f(),
so I have added it, but without luck. Also, I have attempted to access
the data as $db->Record["FIELDNAME"],
$db->Record["TABLENAME.FIELDNAME"], and $db->f("TABLENAME.FIELDNAME").
Sadly, even these exercises prove futile.
I'm a complete virgin to the worlds of PHPLIB, PHP, and general
programming, so I expect my mistake to be a simple one, and I trust your
collective expertise will uncover the error without much exertion.
Double kudos to the clever individual pointing me toward a more elegant
methodology in loading both this and future arrays.
My humble thanks,
wesley
/*
* It's all (elementary) code from here, baby...
*/
// set up variables
global $userdata;
$userdata = array();
$userdata["user_id"] = $auth->auth["uid"];
// execute query
$db = new Sthlurp_Db_Sql;
$db_query = sprintf("select * from users where user_id='%s'",
$userdata["user_id"]);
$db->query($db_query);
// added as suggested
$db->next_record();
// load data into userdata
$userdata["username"] = $db->f("username");
$userdata["firstname"] = $db->f("firstname");
$userdata["lastname"] = $db->f("lastname");
$userdata["email"] = $db->f("email");
$userdata["password"] = $db->f("password");
$userdata["perms"] = $db->f("perms");
// register userdata in session
$sess->register("userdata");
// garbage collection
unset($db_query);
unset($db);
|