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?
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..
Code:
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.
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
Bookmarks