I currently have something for this:
<?php
$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));
?>
Will put something into action:
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
)
)
Is there a mysqli fetch filter (correct term?) That will use the primary key from the result set if it exists as an array index value? In case my question is not clear, this will lead to something, and not to its effect:
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
)
)
It doesn't matter if the values type_idare deleted, but it would be very useful to use the primary key to index the array. I can do this with a fetch loop, but I'm wondering if there is a simpler and more elegant way to handle this.
source
share