Home > Backend Development > PHP Tutorial > Example of how PHP can dynamically display tables_PHP tutorial

Example of how PHP can dynamically display tables_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:24:10
Original
2169 people have browsed it

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 .

www.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...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template