时间:2021-07-01 10:21:17 帮助过:20人阅读
这是php和mysql web开发书中一个例子,目的就是把文件保存的订单信息炸开,用表格显示。我运行时为什么只显示表头,没有表格数据呢。
orders.txt中就是订单信息,用Tab分隔的,已正确读取到$orders中。貌似是后边的for循环中有问题。
//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 "
";
?>