1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Multiple Categories For Blog

Discussion in 'PHP' started by EternalSorrow, Jan 6, 2009.

  1. #1
    I'm currently creating a simple blog/database for an article database. I wish to assign multiple categories, or tags, to each article but I can't seem to figure out how to accomplish this goal.

    I have three tables to work with:
    The history table has fields: entry_id, title, category, sub_category, and info
    The category table merely has fields: category_id, category_name
    And the catjoin table: entry_id, category_id

    The problems that arise are two: the articles are duplicated according to how many categories they have, and I obviously want only a single article shown. For example, if an article were assigned two categories, with the information being stored in the catjoin table, the article would show twice. For some reason the LIMIT command doesn't work.
    Second, I wish to show all categories assigned to a single article at the bottom of that article. To do this I assume I need to create some sort of IF statement which would review the results of the query, determine whether an article had greater than one category assigned in the catjoin table, and output the second category using possibly the IF statement. I have no idea what command, other than a count command, could do this and I'm not sure how to set up such a code (multiple personal attempts have failed miserably).

    I'd be grateful for any help in any form on this problem, as I haven't found any tutorials which described multiple-category blogs. Tutorials are especially appreciated, but this beggar won't be choosy.

    Here's the code for the article PHP:

    @mysql_select_db(db) or die( "Unable to select database");
    $query = "SELECT a.*, b.* FROM (SELECT * FROM history ORDER BY entry_id DESC) a
                INNER JOIN catjoin c ON a.entry_id = c.entry_id
                INNER JOIN category b ON b.category_id = c.category_id";
    $result = mysql_query($query) or die(mysql_error());
    echo '<p><blockquote><div class="title">'.$title.'</div>
    <div class="cat">Categories: <a href="categories.php?category_id='.$category_id.'">'.$category_name.'</A>'.$sub.'</div>
    Code (markup):
    EternalSorrow, Jan 6, 2009 IP