从带有PHP5 / Apache的Ubuntu系统运行,我想键入并填充循环中使用的数组,从位于单个MSSQL服务器上的许多数据库中检索相同的两个字段,然后让它们显示结果一个HTML表格。检索和显示在下面工作,但它一次非常缓慢地检索它们,然后在最后,用所有数据填充HTML表。如何更好地对此进行编码以从数组中检索每个元素并以HTML表格格式(或批量)一次显示一个元素,每个元素的超时为X秒?我正在通过网络搜索加上反复试验来学习PHP,所以请原谅我粗略的编码技巧。
<?php
print "<style> table, th, td { border: 1px solid gray; }</style>";
print "<table><tr><th>CUSTOMER</th><th>Database</th><th>DATE_RECEIVE</th><th>DATE_PROCESS</th></tr>";
$hostname = "sqlserver\instance";
$username = "username";
$password = "password";
MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND.");
$DATABASES01 = array(
"CUSTOMER01" => "CUST01-DB",
"CUSTOMER02" => "CUST02-DB",
"CUSTOMER03" => "CUST03-DB",
"CUSTOMER04" => "CUST04-DB",
);
foreach ($DATABASES01 as $KEY => $DBNAME) {
MSSQL_SELECT_DB($DBNAME) or DIE("Database unavailable");
$QUERY = "SELECT date_receive, date_process FROM table WHERE criteria";
$result = mssql_query( $QUERY );
for ($i = 0; $i < mssql_num_rows( $result ); ++$i) {
$line = mssql_fetch_row($result);
print "<TR><TD>" . $KEY . "</TD><TD>" . $DBNAME . "</TD><TD>" . $line[0] . "</TD><TD>" . $line[1] . "</TD></TR>";
}
}
print "</table>";
?>