www.webdeveloper.com
Results 1 to 3 of 3

Thread: A Blog Category Table

  1. #1
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063

    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?

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    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..

    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.

  3. #3
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063
    Thanks

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles