autoloading of session variables from mysql fields

From: Date: Sat, 20 Oct 2001 10:59:57 +0000
Subject: autoloading of session variables from mysql fields
Groups: php.db 
Request: Send a blank email to php-db+get-13558@lists.php.net to get a copy of this message
Hi, I am trying to write a function that will: - take a list of mysql tables as an array ($sqltables) - take a unique row identifier common to all tables ($rid) - iterate through the $sqltables array and fetch the row for each table where rid = $rid - discover the names of the fields in each table and do session_register for all of them - set the value of each session_registered variable to the row contents for that $rid - go to the next table and do it again, until all tables have been queried and all variables have been discovered and populated I just need some help. Here is what I have written from the top of my head: Thanks in advance, Mike PS: please reply to my address personaly also! ----------------------------------------------- <?php function load_all($rid) { // this is a list of sql tables stored in an array that we will iterate through // and use to populate session variables include("/usr/local/apache/htdocs/survey/inc/sqltables.inc"); for($Index=0;$Index<count($sqltables);$Index++) { // select the database for usage mysql_select_db($db2, $competency_link); // query the table for the row containing $rid $sql_query = mysql_query("SELECT * FROM $sqltables[$Index] WHERE rid = $rid"); $result = mysql_query($sql_query); // fetch the row $myrow = msyql_fetch_array($result); // return the values of each fieldname as variables with same name // count the fields in the row $num_fields = mysql_num_fields($myrow); for($fieldindex=0;$index<count($num_fields);$fieldindex++) { // return the field names $fieldname = mysql_field_name($num_fields[$fieldindex]); // return the values of each fieldname as variables with same name session_register('fieldname'); } } } ?>

« previous php.db (#13558) next »