How to classify an article submitted to sql database?

How to classify an article submitted to the sql database so that the user wants to publish the article in a particular category, they are provided with a drop-down menu to choose which article to publish in this category. About Us, Products, and Support - Example Categories

<form method="post" action="postArticle.php">
<p>
    <select name="selectedOption">
        <optgroup label="About us">
            <option value="about">About us</option>
        </optgroup>

        <optgroup label="Products">
            <option value="foo">Foo</option>
            <option value="oof">Oof</option>
        </optgroup>

        <optgroup label="Support">
            <option value="support">Support</option>
        </optgroup>
    </select>
</p>
+5
source share
2 answers

At first glance, it seems that you just need a simple table to implement a structure that allows you to create a nested array of category structure. Any category c parent_id == 0is optgroup, and then you will list each subcategory as optioninside each parent optgroup.

category_id    | parent_id    | category_name
1              | 0            | About us
2              | 1            | About us
3              | 0            | Products
4              | 3            | foo
5              | 3            | oof
6              | 0            | Support
7              | 6            | Support

This will display as:

<form method="post" action="postArticle.php">
<p>
    <select name="selectedOption">
        <optgroup label="About us">
            <option value="2">About us</option>
        </optgroup>

        <optgroup label="Products">
            <option value="4">Foo</option>
            <option value="5">Oof</option>
        </optgroup>

        <optgroup label="Support">
            <option value="6">Support</option>
        </optgroup>
    </select>
</p>

, select , . , , (, , ). , ( ), , , , optgroup . , ( ) option , , , .

+1

Category, . , , category_id . .

. , .

0

All Articles