class TableData {
public $table_name;
function TableName()
{
global $mysqli;
$sql="select table_name from tools where id='$_POST[table_id]'";
if(!$query=$mysqli->query($sql))
{
$err=$mysqli->errno.': '.$mysqli->error;
trigger_error($err, E_USER_WARNING);
}
$row=$query->fetch_object();
$the_name=$row->tool_name;
$this->table_name=$the_name;
}
function TableInfo()
{
global $mysqli;
$sql = "show columns from $table_name";
$query = $mysqli->query($sql);
if(!$query)
{
$error = $mysqli->errno.': '.$mysqli->error;
trigger_error($error, E_USER_WARNING);
}
$data_count=mysqli_num_rows($query);
if($data_count==0)
{
trigger_error("you don't have any column names", E_USER_WARNING);
}
//return $data_count;
while($show_columns=$query->fetch_object())
{
$the_columns[]=$show_columns->Field;
}
return $the_columns;
}
}
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
ASKER
I had already seen the example you referenced on the Wiki page. Thing is, I couldn't figure out how to do it in the context of my scenario.
Going back to that for a moment, I was able to get it to work. Here's my Class:
Open in new window
And then here's what I instantiated things so I could get my needed result:
$table_stuff=new TableData;
$table_handle=$table_stuff
$columns = $table_stuff->TableInfo($t
It works! But if I were looking to something a little more elegant / streamlined and I wanted one call, one Class and one result, how would that look? Can that be done?