Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

category and sub category

Participant ,
Dec 02, 2008 Dec 02, 2008
Hi I have table where i want to display the categories with parent id 0 and When parent id is 1 or 2 and so on...

it should display as :

autos/auto1
autos/cars

Etc:

My database table is like this:

cid int(11) No auto_increment
parentid int(11) No 0
img varchar(30) latin1_swedish_ci No
title varchar(40) latin1_swedish_ci No
cdesc text latin1_swedish_ci No
hits

Currently it is diaplying straight as:

categories
and after finish of main categories .

sub ategories start.

i am using the query as;

select cid, title, parentid
from grcat
order by cid

<cfselect name="category" label="Select Category: " value="cid" display="title" query="getCats" tabindex="1" tooltip="Chooose Your category"></cfselect>

i want is my subcategories should show after their maincategory

like:

autos/car
autos/files

in the same single select.

I trying it but no possible solution working me instead
544
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 02, 2008 Dec 02, 2008
Hi,

Concatenate your maincategory and subcategory (place a "/" between them) as "title" in your "getCats" query

SELECT maincategory + '/' + subcategory as title,your_other_columns FROM getCats

and then do the display in your <cfselect> as,

<cfselect name="category" label="Select Category: " value="cid" display="title" query="getCats" tabindex="1" tooltip="Chooose Your category"></cfselect>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2008 Dec 03, 2008
Thanks Dude. Bu the The gravity of Situation is here that I have category and Subcategory under one column and that is title.

That i want to show as i have parentid field within the table as:

cid, parentid, img, title, desc

So title values having parentid of 0 are main categories
and once the next set of categories whose parentid stat from 1,2,3 are sub categories.

I am bit confused at this
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 03, 2008 Dec 03, 2008
Hi,

Try replacing your existing order by clause with parentid,cid asc;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2008 Dec 03, 2008
LATEST
Hi,

There's a lot of nice info in this article:
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

What I usually do is to save a node-sort and node-indent value into the database. That helps out a lot with dealing with nested-set problems. It's not fully normalized, but the sort and indent values can always get re-created whenever you do any changes to the tree structure.

cheers,
fober
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources