0
我想將表單中的數據存儲到二維數組 ,但它似乎有問題插入數據到數組中。 如果我是爲了呼應$ orderArray [0] [$ COUNT2]似乎工作 但如果我是爲了呼應$ orderArray [1] [$ COUNT2]會出現錯誤問題php二維數組
$dateArray = array();
$orderArray = array(array());
$amountArray = array(array());
$count = 0;
$count2 = 0;
foreach ($_POST['export'] as $date){
$dateArray[$count] = $date;
include "/storescript/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM ordera WHERE orderDate = '$date' ORDER BY orderid ASC");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$orderArray[$count][$count2] = $row["orderAmount"];
$amountArray[$count][$count2] = $row["itemAmount"];
$count2++;
}
}
$count++;
}
取決於您的數據BU首先,您可以將'$ count ++;'移動到您的if($ productCount> 0){'塊,因爲如果您的產品數量爲0,則不會向您的任何元素添加任何元素數組 – Vytautas
你能更清楚地知道你想要什麼嗎?順便說一句,您的輸入不安全...... – ibi0tux
您不需要包含連接文件很多次。 – hjpotter92