从数据库里取出数据放到表格里php有本身的方法,如odbc_result_all(),该函数用来将取得的资料转成HTML 的表格 (table) 格式,但必须是SQL语句里的选出来的字段,可能显示的数据并不是你全部选的字段。另一些可能要做选择,或者判断的。所以我写了这段代码来生成一个表格。想要显示的字段完全由一个数组控制。而且可以根据需要改变数组里的某个字段的值。代码如下:
/* showtable.php
*
* Created by Xu Jie
* Date: 03/01/2001
*/
function showHeader($arr_header)
{
$col = sizeof($arr_header);
echo "
";
do
{
echo "
}
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 " ";
}
?>
其中用户需要调用的是showTable()函数。
参数$arr_header为表格头部的标题行。比如一个用户列表(UserName,Password,EmailAdd,Homepage),存
放在sql Server上,从数据库里用mssql_fetch_object()取出字段存放到一个数组$arr_list里后,如果只
想显示UserName,EmailAdd,HomePage三个字段,而不显示Password字段。
$arr_header就可以这样写:
$arr_header = array("UserName"=>"用户名","EmailAdd"=>"电子邮件","Homepage"=>"个人主页");
然后调用showTable($arr_header,$arr_list;"Border=2");
就可以把列表显示到网页上了。为以下显示:
用户名 电子邮件 个人主页
...... ........ ........
...... ........ ........
...... ........ ........
如果想在每个电子邮件上都加链接 就可以用一个循环在给EmailAdd一列的每一个都加上链接了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.