So I want to build a category script for products.
How I can build the category tree?
I have a DB like this...
CREATE TABLE categories (
cat_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
parent_id integer NOT NULL,
cat_name CHAR(24) NULL DEFAULT NULL,
cat_position tinyint NOT NULL,
icon TEXT NULL DEFAULT NULL,
keywords text NOT NULL, //for search
active boolean NULL DEFAULT true,
cat_description CHAR(128) NULL DEFAULT NULL
);
But I can't understand how it works because 1 product may be found in many categories...
I am coding on GoLang
Now I do like this...
rows, err := db.Query("SELECT cat_id, parent_id, cat_name FROM categories WHERE active = true ORDER BY Parent_id ASC")
if err != nil {
http.Error(w, http.StatusText(500), 500)
return
}
defer rows.Close()
Then I put rows into template...
{{range .}}
<p><a href="/show?getinfo={{ .Cat_id}}">{{ .Cat_id}}</a> - {{ .Parent_id}} - {{ .Cat_name}} <a href="/show?getinfo={{ .Cat_id}}">Показать</a>
{{end}}
In the end I would like to get something similar to this