Well,
It truly is a small world. I was born in Weisbaden, Germany.
At any rate, I would like to be able to produce a table automatically (magically) regardless of the number of columns.
I have a PERSON table and an ENTITY table, among others, with anywhere from 2 to 34 columns in a table. I (or any end-user) will likely want to ask the database for a variety of reports using any number of columns. It's easy enough to create predefined queries with the columns already arranged to be placed into HTML tables for display.
I don't mean to be lazy, but I really didn't much enjoy coding the HTML table for the PERSON table (the BIG 34) results. Besides, I may only want five or ten of those fields at any given time.
Here's a hard-coded result (HTML)table:
mysql_select_db("chadb_test");
$query = "select * from entity";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p align='center'>Number of entities found: ".$num_results."</p>";
?>
<div>
<table align='center' border='0' cellpadding='2'>
<tr>
<th>Entity ID</th>
<th>Entity Type</th>
<th>Entity Category</th>
<th>Entity Name</th>
<th>Address ID</th>
</tr>
<?php
while ($query_data = mysql_fetch_array($result))
{
$ent_id = $query_data["ent_id"];
$ent_type = $query_data["ent_type"];
$ent_cat = $query_data["ent_cat"];
$ent_name = $query_data["ent_name"];
$adrs_id = $query_data["adrs_id"];
echo "<tr>\n";
echo "<td align='center'>$ent_id</td>\n";
echo "<td align='center'>$ent_type</td>\n";
echo "<td align='center'>$ent_cat</td>\n";
echo "<td align='center'>$ent_name</td>\n";
echo "<td align='center'>$adrs_id</td>\n";
}
Suppose I want - one day down the road - to pull data from both the ENTITY and PERSON tables, using only certain columns? Entities could be family names or business names, other churches, etc.
Even if I have done my homework and pre-determined the kinds of reports I'll need, it seems I should NOT have to hard-code the columns for every situation.
Should I use a function, or a class with one function for determining how many columns have been requested by the end-user, and another for building the HTML table based on the output of the first function?
Thanks. I hope this makes clearer what I'm trying to do.