the answer is that it's both.
you need to have a "category_id" in the posts table, assuming that each post can only have 1 category, and that category_id should be a foreign key referencing the category_id field in the categories table.
then when you're querying the table, you would use a join, something like this..
select p.column_list, c.column_list
from posts p
inner join categories c on c.category_id = p.category_id
I don't get why you're talking about the Mysqli functions.