我必須使用MySQL表得到表值,即使用其他表。我得到了數組值Mysql的陣列中的數據不顯示錶
值第一表查詢:
$ordersdetail = "SELECT * FROM `order_item` WHERE `Order_ID`='".$orderid ."'";
$customerorder = mysql_query($ordersdetail);
$i=0;
while($rows = mysql_fetch_array($customerorder))
{
$orderproduct= $rows['Order_product_ID'];
$orderids= $rows['Order_ID'];
$productId[$i] = $rows['Product_ID'];
$sizeId[$i] = $rows['Size_ID'];
$colorId[$i] = $rows['Color_ID'];
$quantiy = $rows['Order_Quantity'][$i];
$price = $rows['Unit_Price'][$i];
$subTotal = $rows['Sub_Total'];
$customerccode = $rows['Record_Status'];
$customerphone = $rows['Created_Time'];
$i++;
}
表列的productid陣列值獲得使用的另一種表:
給出:
for($i=0;$i<count($productId);$i++)
{
$product = "SELECT * FROM `product` WHERE `Product_ID`='".$productId[$i]."'";
$products = mysql_query($product);
while($rows = mysql_fetch_array($products))
{
$productnames = $rows['Product_Name'];
}
}
color id used :
for($i=0;$i<count($colorId);$i++)
{
$color = "SELECT * FROM `color` WHERE `Color_ID`='".$colorId[$i] ."'";
$cname = mysql_query($color);
while($rows = mysql_fetch_array($cname))
{
$colorname = $rows['Color_Name'];
}
}
相同的方式使用的值表
個我的問題,這顯示值表continuely
table structure
$message .= "<table width='100%' border='1' cellspacing='0' cellpadding='1'>
<thead>
<tr style='background: #eee;'>
<th><strong>Quantity</strong> </th>
<th><strong>ProductName</strong> </th>
<th><strong>Size</strong> </th>
<th><strong>Style</strong> </th>
<th><strong>Price</strong> </th>
<th><strong>Total</strong> </th>
</tr>
";
for($i=0;$i<count($productId);$i++)
{
$message .=" <tr style='color: #c40000;'>
<th>" .$quantiy. "</th>
<th>" .$productnames. "</th>
<th>" .$sizename. "</th>
<th>" .$colorname. "</th>
<th>" . $price. "</th>
<th>" . $subTotal. "</th>
</tr>";
}
這種格式是不顯示正確的更值僅第一個值顯示多個時
你的循環每次都打印相同的東西,如果你想要不同的東西,你需要告訴它打印一些不同的東西。真的,你應該把你的產品列表放到一個數組中,然後循環數組,現在,上面是隻是字符串。例如$數量,沒有什麼改變到產品的數量2 – Anigel
請閱讀[正確的SQL轉義](http://bobby-tables.com/php),因爲你可能有一些嚴重的[SQL注入漏洞]( http://bobby-tables.com/)。使用'mysql_query'也是一個壞主意,因爲它將在未來版本的PHP中被刪除。 PDO是一種更易於正確使用的現代替代品。 – tadman