php
這是php和mysql web開發書中一個例子,目的就是把檔案儲存的訂單資訊炸開,用表格顯示。我運行時為什麼只顯示表頭,沒有表格式資料呢。
orders.txt中就是訂單資訊,用Tab分隔的,已正確讀取到$orders中。貌似是後邊的for迴圈中有問題。
Bob's Auto Parts - Customer Orders
Bob's Auto Parts
Customer Orders
//Read the entire file
//Each order becomes an element in the array
$orders = file("./orders.txt");
//count the number of orders in the array$number_of_orders = count($orders);if($number_of_orders = 0) { echo "No orders pending. Please try again later.
";}echo "
\n";echo "
Order Date |
Tires |
Oil |
Spark plugs |
Total |
Address |
";for($i = 0; $i < $number_of_orders; $i++) { //Split up each line $line = explode("\t", $orders[$i]); //keep only the number of items ordered $line[1] = intval($line[1]); $line[2] = intval($line[2]); $line[3] = intval($line[3]); //output each other echo "
".$line[0]." |
".$line[1]." |
".$line[2]." |
".$line[3]." |
".$line[4]." |
".$line[5]." |
";}echo "
";
?>