目前,我有話要的效果:是否有一個「mysqli_fetch_all」使用列(PK)作爲結果數組中的索引?
<?php
// ...More Code
$result = mysqli_query($mysqli, "SELECT * FROM stock_types");
if(!$result || mysqli_num_rows($result) < 1) die('error');
$stock_types = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
die(print_r($stock_types,true));
// More Code...
?>
將輸出的東西效果:
Array (
[0] => Array (
[type_id] => 1
[type_name] => In Stock
[type_visible] => 1
[type_locked] => 0
)
[1] => Array (
[type_id] => 2
[type_name] => Out of Stock
[type_visible] => 1
[type_locked] => 1
)
[2] => Array (
[type_id] => 3
[type_name] => Offline
[type_visible] => 0
[type_locked] => 1
)
[3] => Array (
[type_id] => 5
[type_name] => Hidden
[type_visible] => 0
[type_locked] => 0
)
)
是否有mysqli的提取過濾器,將使用的主鍵從(正確的說法?)結果集,如果一個作爲數組索引值存在?如果我的問題不明確,將導致東西,而不是對他的影響:
Array (
[1] => Array (
[type_name] => In Stock
[type_visible] => 1
[type_locked] => 0
)
[2] => Array (
[type_name] => Out of Stock
[type_visible] => 1
[type_locked] => 1
)
[3] => Array (
[type_name] => Offline
[type_visible] => 0
[type_locked] => 1
)
[5] => Array (
[type_name] => Hidden
[type_visible] => 0
[type_locked] => 0
)
)
這不是必不可少的要刪除的type_id
值,但如果主鍵可用於索引這將是超級有用陣列。我可以用一個抓取循環來做到這一點,但我想知道是否有更簡單更優雅的處理方式。
猜猜我必須堅持循環。感謝指導Bill。 – RedYetiCo