我有一個HTML表格這種類型的記錄:只剩下最後一個元組填充分隔的文件用PHP
<tr class="simplehighlight" onclick="window.location.href='./games/game191.php';">
<td>06/09/2007</td><td>Jennifer Woods Memorial Grand Prix</td><td>C54</td>
<td>Nikolayev, Igor</td><td>2431</td><td>Parry, Matt</td><td>2252</td><td class="text-center">1-0</td></tr>
我想在一個分隔的文件讀取,使一個數組,並填充表:(樣本唱片)
game191|06/09/2007|Jennifer Woods Memorial Grand Prix|C54|Nikolayev, Igor|2431|Parry, Matt|2252|1-0
我嘗試這樣做,但它只能從數據文件(/games.csv
)
<?php
// open delimited data file "|" if needed and read.
//game191|06/09/2007|Jennifer Woods Memorial Grand Prix|C54|Nikolayev, Igor|2431|Parry, Matt|2252|1-0
if(!isset($_SESSION['games_array'])) {$file = $_SERVER['DOCUMENT_ROOT'].'/games.csv';
$fp = fopen($file,"r"); $list = fread($fp, filesize($file));
$_SESSION['games_array'] = explode("\n",$list); fclose($fp);}
// extract variables from each tuple by iteration
foreach ($_SESSION['games_array'] as $v);{
$token = explode("|", $v);
//write the table row and table data
echo "<tr class=\"simplehighlight\" onclick=\"window.location.href='./games/";
echo $token[0]; echo ".php';\">";
echo "<td>";echo $token[1];echo "</td>"; echo "<td>";echo $token[2];echo "</td>";
echo "<td>";echo $token[3];echo "</td>"; echo "<td>";echo $token[4];echo "</td>";
echo "<td>";echo $token[5];echo "</td>"; echo "<td>";echo $token[6];echo "</td>";
echo "<td>";echo $token[7];echo "</td>";
echo "<td class=\"text-center\">"; echo $token[8];echo "</td>";
echo "</tr>";};
?>
顯示的最後一個記錄
我錯過了什麼?
如果每次我犯了這個錯誤,我都有一毛錢......好吧,反正我有幾毛錢。 – AgentConundrum 2010-12-09 23:41:36
鋒利的眼睛爲+1 – devrooms 2010-12-09 23:41:54