A Blog Category Table
A posts table would have the following information in the database: post_id, title, author, date, body. It would also have a category (such as "music," to just give an example), which would also need to be displayed on the blog. However, the category isn't in the posts table, but rather in the categories table. How would you get the proper category to display with your blog post when the database output it to the browser? I'm guessing that it's either done via a JOIN query or through the use of foreign keys, but if it's either one of those, I have no idea where to begin. Could someone give me an example?
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..
I don't get why you're talking about the Mysqli functions.
select p.column_list, c.column_list
from posts p
inner join categories c on c.category_id = p.category_id
P.S. The MySQLI stuff is in my signature. The thing was, whenever I had SQL trouble and posted for help, a lot of people would look at the MySQLI syntax and assume that's why the code wasn't processing. Finally, I got sick of that happening, and put that in my signature
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)