所以我從有我有不同的電腦電腦1個表產品信息的文本文件中讀取顯示錶1是從文件1讀取,計算機2顯示錶2是從讀文件2,等等等等,但對於從表2中的某些原因,電腦3 & 4展會信息,並3 & 4我還沒有一點頭緒什麼在希望我的代碼可以提供更好的視野去。重複數據從文件
表1
<?php
error_reporting(E_ALL^E_NOTICE);
$row = 0;
$sortby ='';
$sortkey='';
echo '<h1><span class="sortby"></span></h1>
<table cellspacing="5" summary="QA Tables">
<tr>
<th>Products</th>
<th>Types</th>
<th>Keys</th>
<th>Date & Time Added</th>
</tr>';
$fp = fopen('key_QA_N1.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
while (!feof($fp)) {
$line = fgets($fp,1024); //use 2048 if very long lines
$row++;
list ($products,$types, $keys, $date) = explode('|', $line);
if ($sortby == 'Products') $sortkey = strtolower($products);
if ($sortby == 'Types') $sortkey = strtolower($types);
if ($sortby == 'Keys') $sortkey = strtolower($keys);
if ($sortby == 'Date & Time Added') $sortkey = strtolower($date);
$col[$row] = array($sortkey, $products, $types, $keys, $date);
}
fclose($fp);
$arrays = count($col) - 1;
$loop = 0;
while ($loop < $arrays) {
$loop++;
echo '
<tr>
<td>'.$col[$loop][1].'</td>
<td>'.$col[$loop][2].'</td>
<td>'.$col[$loop][3].'</td>
<td>'.$col[$loop][4].'</td>
</tr>';
}
echo '
</table>
'
?>
表2
<?php
error_reporting(E_ALL^E_NOTICE);
$row = 0;
$sortby ='';
$sortkey='';
echo '<h1><span class="sortby"></span></h1>
<table cellspacing="5" summary="QA Tables">
<tr>
<th>Products</th>
<th>Types</th>
<th>Keys</th>
<th>Date & Time Added</th>
</tr>';
$fp = fopen('key_QA_N2.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
while (!feof($fp)) {
$line = fgets($fp,1024); //use 2048 if very long lines
$row++;
list ($products,$types, $keys, $date) = explode('|', $line);
if ($sortby == 'Products') $sortkey = strtolower($products);
if ($sortby == 'Types') $sortkey = strtolower($types);
if ($sortby == 'Keys') $sortkey = strtolower($keys);
if ($sortby == 'Date & Time Added') $sortkey = strtolower($date);
$col[$row] = array($sortkey, $products, $types, $keys, $date);
}
fclose($fp);
$arrays = count($col) - 1;
$loop = 0;
while ($loop < $arrays) {
$loop++;
echo '
<tr>
<td>'.$col[$loop][1].'</td>
<td>'.$col[$loop][2].'</td>
<td>'.$col[$loop][3].'</td>
<td>'.$col[$loop][4].'</td>
</tr>';
}
echo '
</table>
'
?>
表3
<?php
error_reporting(E_ALL^E_NOTICE);
$row = 0;
$sortby ='';
$sortkey='';
echo '<h1><span class="sortby"></span></h1>
<table cellspacing="5" summary="QA Tables">
<tr>
<th>Products</th>
<th>Types</th>
<th>Keys</th>
<th>Date & Time Added</th>
</tr>';
$fp = fopen('key_QA_N3.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
while (!feof($fp)) {
$line1 = fgets($fp,1024); //use 2048 if very long lines
$row++;
list ($products1,$types1, $keys1, $date1) = explode('|', $line1);
if ($sortby == 'Products') $sortkey = strtolower($products1);
if ($sortby == 'Types') $sortkey = strtolower($types1);
if ($sortby == 'Keys') $sortkey = strtolower($keys1);
if ($sortby == 'Date & Time Added') $sortkey = strtolower($date1);
$col[$row] = array($sortkey, $products1, $types1, $keys1, $date1);
}
fclose($fp);
$arrays = count($col) - 1;
$loop = 0;
while ($loop < $arrays) {
$loop++;
echo '
<tr>
<td>'.$col[$loop][1].'</td>
<td>'.$col[$loop][2].'</td>
<td>'.$col[$loop][3].'</td>
<td>'.$col[$loop][4].'</td>
</tr>';
}
echo '
</table>
'
?>
表4
<?php
error_reporting(E_ALL^E_NOTICE);
$row = 0;
$sortby ='';
$sortkey='';
echo '<h1><span class="sortby"></span></h1>
<table cellspacing="5" summary="QA Tables">
<tr>
<th>Products</th>
<th>Types</th>
<th>Keys</th>
<th>Date & Time Added</th>
</tr>';
$fp = fopen('key_QA_N4.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
while (!feof($fp)) {
$line2 = fgets($fp,1024); //use 2048 if very long lines
$row++;
list ($products2,$types2, $keys2, $date2) = explode('|', $line2);
if ($sortby == 'Products') $sortkey = strtolower($products2);
if ($sortby == 'Types') $sortkey = strtolower($types2);
if ($sortby == 'Keys') $sortkey = strtolower($keys2);
if ($sortby == 'Date & Time Added') $sortkey = strtolower($date2);
$col[$row] = array($sortkey, $products2, $types2, $keys2, $date2);
}
fclose($fp);
$arrays = count($col) - 1;
$loop = 0;
while ($loop < $arrays) {
$loop++;
echo '
<tr>
<td>'.$col[$loop][1].'</td>
<td>'.$col[$loop][2].'</td>
<td>'.$col[$loop][3].'</td>
<td>'.$col[$loop][4].'</td>
</tr>';
}
echo '
</table>
'
?>
親切的問候E.P
你的意思是重置陣列內容$山坳=陣列(); – 2010-11-29 13:07:26
感謝。我一直在使用Ruby過長:P – rwilliams 2010-11-29 13:08:25