Correction...Forgot a ; //Find User Configuration $sql = mysql_query("SELECT field_name FROM config WHERE show_field=1") OR die("Could not query database: ".mysql_error().""); while($result = mysql_fetch_array($sql, MYSQL_ASSOC)){ $field_name_array[] = $result['field_name']; }
// Iterate through array and print fields if($field_name_array == ""){ print 'please select at least 1 field to be shown'; } else { for($i=0, $n=sizeof($field_name_array); $i<$n; $i++){ print $field_name_array[$i]; } } -----Original Message----- From: Ralph Guzman [mailto:[EMAIL PROTECTED] Sent: Monday, July 28, 2003 4:24 AM To: 'Jason Martyn'; [EMAIL PROTECTED] Subject: RE: [PHP] Problem setting variables. //Find User Configuration $sql = mysql_query("SELECT field_name FROM config WHERE show_field=1") OR die("Could not query database: ".mysql_error().""); while($result = mysql_fetch_array($sql, MYSQL_ASSOC)){ $field_name_array[] = $result['field_name'] } // Iterate through array and print fields if($field_name_array == ""){ print 'please select at least 1 field to be shown'; } else { for($i=0, $n=sizeof($field_name_array); $i<$n; $i++){ print $field_name_array[$i]; } } -----Original Message----- From: Jason Martyn [mailto:[EMAIL PROTECTED] Sent: Sunday, July 27, 2003 9:22 PM To: [EMAIL PROTECTED] Subject: [PHP] Problem setting variables. I'm creating a script that filters the table of results from a database based on the configuration set by the user (config stored in database as well). For example a table has 30 columns. However the user need only see 5. Every user is different so a user configuration is stored in the database. The database has 2 columns: field_name and show_field. field_name is the name of the field (obviously) that is shown in the table. show_field can either be a 1 or a 0. 1 = show field. 0 = don't show field. I'm getting to a certain point. But I'm not sure how I can go about setting variables for each field_name that has a show_field value of 1. Heres the code. <?php function Interactive() { //Database Variables include ( "include/db_config.inc" ); //Database connection. $connect = mysql_connect($host, $login, $passwd) OR die("Could not connect to MySQL Database: ".mysql_error().""); mysql_select_db("admin", $connect) OR die("Could not select Database: ".mysql_error().""); //Find User Configuration $sql = mysql_query("SELECT field_name FROM config WHERE show_field=1") OR die("Could not query database: ".mysql_error().""); $result = mysql_fetch_array($sql, MYSQL_ASSOC); //Make sure there are fields to be shown. if(count($result) > 0) { //*****************************************************// // Here is where I would like to set variables. // I first thought of using a for statement, but // realized that variables cannot begin with a // number. Is there any possible way to set // variables for the array results of my query? //*****************************************************// } else { die("Please select at least 1 field to be shown."); } } ?> Thanks, Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php