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