This is probably pretty basic, but I’m a beginner in PHP – I have one table for categories (cat_id is the primary key & cat_name is the only other field), and another table for posts which uses the cat_id as a foreign key.
My question is when creating a form for a user to submit a new post, how do I get the list of already created categories to appear in the form (by their category name) by way of a drop down box?
I’m assuming I’ll have to select the table, assign values/variables to the data, or make it an array of some sort and then print the data in a table for the user to select?
There is no restriction on running queries for one table when you’ve already run a query for another. Use a simple
SELECT * FROM category, perhaps with anORDER BYclause. I’m assuming you’re using mysql or mysqli, so use a while loop to go through the results:You’ll end up with a html string
$selectthat you canechowherever you like, as many times as you like.