What I am basically trying to do is run through a loop to look through all inventory slots in the player's inventory and figure out what item ids they are and throwback item names when the player goes onto the inventory page, I have that working.
The issue comes when I want to include quantity and I want to iterate through every slot_x_quantity table in the database in one fell swoop, but I keep getting errors like
Undefined index: 'slot_1_quantity''
I am putting $selectstatement in the query to find the quantities because I want to be able to go through slot_x_quantity 1-9 in the loop.
I've tried not even having $selectstatement and doing $query = "SELECT slot_'$indexaddone'_quantity FROM inventory WHERE char_id='$char_id'";
But then $result throws false, as if it is not able to find the table(s).
foreach($char_inv_slots as $key=>$value) {
if($value != 0) {
$item_id = $value;
$query = "SELECT item_name FROM items WHERE id='$item_id'";
$result = mysqli_query($db, $query);
$row = $result->fetch_assoc();
$item_name = $row['item_name'];
$indexaddone = (int)$key + 1;
$selectstatement = "slot_" . $indexaddone . "_quantity";
$query = "SELECT '$selectstatement' FROM inventory WHERE char_id='$char_id'";
$result = mysqli_query($db, $query) or die($query->error);
$row = $result->fetch_assoc();
$item_quantity = $row["'$selectstatement''"];
if($value == 8001) {
echo($item_name . " - " . $item_quantity);
} else {
echo($item_name . "<br>");
}
I want, on my inventory page, to see the " - " with only items that are stackable, but I can't seem to get the quantitys to show through this loop.