This code looks like it is quite messed up.
I am assuming you have two tables Items and Inventory.
And you want to select all items for one particular person or user. It could be done with one select statement, looking like that:
SELECT Name, Amount FROM items, inventory WHERE inventory.id = items.inventory_id AND inventory.username ='$username' an items.amount > 0
but it really depends on the database structure, if I am wrong, please post your DB structure here.