PHP can dynamically display the example of a table _php tutorial

Source: Internet
Author: User
Take the data from the database and put it in the table. PHP has its own method, such as Odbc_result_all (), which is used to convert the obtained data into an HTML table format, but it must be the selected field in the SQL statement, and the data that may be displayed is not the field you have selected. Others may have to choose, or judge. So I wrote this code to generate a table. The field you want to display is controlled entirely 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 "";
}
?>
Where the user needs to invoke the Showtable () function.
The parameter $arr_header is the header row of the table header. such as a list of users (Username,password,emailadd,homepage),

On SQL Server, Mssql_fetch_object () takes out the field from the database and stores it in an array $arr_list, if only

You want to display username,emailadd,homepage three fields without displaying the password field.
$arr _header can write like this:
$arr _header = Array ("UserName" and "User name", "Emailadd" and "e-mail", "homepage" and "personal homepage");
Then call Showtable ($arr _header, $arr _list; " Border=2 ");
You can display the list on the page. is displayed for the following:

User name Email Personal home Page
...... ........ ........
...... ........ ........
...... ........ ........

If you want to add a link to each e-mail message, you can use a loop to add a link to each of the Emailadd columns.

http://www.bkjia.com/PHPjc/532162.html www.bkjia.com true http://www.bkjia.com/PHPjc/532162.html techarticle take the data from the database and put it in the table. PHP has its own method, such as Odbc_result_all (), which is used to convert the obtained data into an HTML table format, but it must be in an SQL statement ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.