PHP has its own methods for fetching data from the database and putting it into tables, such as odbc_result_all(). This function is used to convert the obtained data into HTML table format, but it must be the selected fields in the SQL statement. The data displayed may not be all the fields you selected. Others may have to make choices or make judgments. So I wrote this code to generate a table. The fields you want to display are entirely controlled by an array. And you can change the value of a field in the array as needed. The code is as follows:
/* showtable.php
*
* Created by Xu Jie
* Date: 03/01/2001
*/
function showHeader ($arr_header)
{
$col = sizeof($arr_header);
echo "
";
do
{
echo "
".pos($arr_header)." |
";
}
while (next($arr_header));
echo "
";
}
function showList($head,$arr_data)
{
$i=0;
do
{
$header[$i++] = key($head);
}
while (next($head));
for ($i=0;$i
{
if ($i%2==0)
echo "
";
else
echo "
";
for ($j=0;$j{
if ($arr_data[$i]->$header[$j]!=" ")
echo " ".$arr_data[$i]->$header[$j]."
";
else
echo " ";
}
echo "
";
}
}
function showTable($arr_header,$arr_list,$face="BORDER=1")
{
echo "
";
showHeader($arr_header);
showList($arr_header,$arr_list);
echo "
";
}
?>
What the user needs to call is the showTable() function.
The parameter $arr_header is the header row of the table header. For example, a user list (UserName, Password, EmailAdd, Homepage), store
on the sql Server, use mssql_fetch_object() to fetch the fields from the database and store them in an array $arr_list. If only
wants to display UserName, EmailAdd, HomePage field, instead of displaying the Password field,
$arr_header can be written like this:
$arr_header = array("UserName"=>"Username","EmailAdd"=>"Email","Homepage" =>"Personal homepage");
Then call showTable($arr_header,$arr_list;"Border=2");
The list can be displayed on the web page as follows:
Username Email Profile
… ........ ........
… ........ . .......
...... ........ ........
If you want to add a link to every email You can use a loop to add links to each item in the EmailAdd column .
http://www.bkjia.com/PHPjc/532162.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532162.htmlTechArticleFetch data from the database and put it into the table. PHP has its own methods, such as odbc_result_all(). This function is used to Convert the obtained data into HTML table format, but it must be in a SQL statement...