I am trying to insert data into a multidimensional array from two tables in my database, but it does something that I don't really know how to fix.
First of all, here is my PHP script:
if ($stmt = $mysqli->prepare('SELECT objects_price.object_id, materials.material_id, materials.name, material_amount
FROM objects_price
INNER JOIN materials ON objects_price.material_id=materials.material_id
')) {
$stmt->execute();
$stmt->bind_result($object_id, $material_id, $material_name, $material_amount);
$j = 1;
$arr = array();
while ($stmt->fetch()) {
$k = 1;
if ($object_id == $k) {
$arr[] = array($j, $material_name, $material_amount);
$k++;
$j++;
}
}
$stmt->close();
This script takes out some values from the database and inserts them in the array. My database looks like this: (objects_price)
(materials)
What happens right now is that it only outputs:
If I change the database query to:
if ($stmt = $mysqli->prepare('SELECT objects_price.object_id, materials.material_id, materials.name, material_amount
FROM objects_price
INNER JOIN materials
')) {
it outputs this:
So the left side of this table is shown correct, but the right side shows only the first row of the price, (47). It should look like this:
I don't know if this is easily achieveable by changing the database query. But I hope I can get some advice, suggestions or help in here. Thanks in advance.