3 Replies - 439 Views - Last Post: 02 April 2015 - 09:20 AM

#1 Mohsin01   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 13-April 12

getting data from category table for a forum?

Posted 02 April 2015 - 07:56 AM

hi guys i'm working in php, Im trying to get get all category names from table with their parent name and and putting these values in html drop down. i can get the data into the drop down. but data is not in the order as i want it to be. i want that each category should come under its parent id. right now results are like this
CatID	CatName	PID
1	Medical	0
2	MBBS	1
3	BDS	1
4	1styear	2
6	1styear	3


where as i want data to apear like this
CatID	CatName	 PID
1	Medical	 0
2	MBBS	 1
4	1styear	 2
3	BDS	 1
6	1styear	 3


i've tried but no luck, please help what query i should be using or what method.

Thanks!

This post has been edited by Mohsin01: 02 April 2015 - 08:20 AM


Is This A Good Question/Topic? 0
  • +

Replies To: getting data from category table for a forum?

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6834
  • View blog
  • Posts: 28,360
  • Joined: 12-December 12

Re: getting data from category table for a forum?

Posted 02 April 2015 - 08:01 AM

I don't understand that order. Perhaps you could explain why the two 1styear items don't appear next to each other?
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6834
  • View blog
  • Posts: 28,360
  • Joined: 12-December 12

Re: getting data from category table for a forum?

Posted 02 April 2015 - 08:06 AM

If you need a custom sort order then I provided an answer for this at SO.
Was This Post Helpful? 0
  • +
  • -

#4 Mohsin01   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 13-April 12

Re: getting data from category table for a forum?

Posted 02 April 2015 - 09:20 AM

View Postandrewsw, on 02 April 2015 - 03:01 PM, said:

I don't understand that order. Perhaps you could explain why the two 1styear items don't appear next to each other?


i try to explain,
this table is for forum categories, at the time of inserting new category in the category table, this new category could be sub category of some category. so i give a list of categories to the user to select your parent category to make new child category in it. i'm populating drop down with all the categories. so far so good.

but the problem occurs when i want to sort them in drop down. for example there are two 1st-year category, one is for mbbs and one is for bds. when we click on the drop down we don't know which 1st year belongs to mbbs and which belongs to bds.

so, i want that child of parent categories should appear under them. like , MBBS has 3 childs 1st-year, 2nd-year and 3rd year.
and for bds as well. what query i should be using for this? check pictures as well. first tells my problem and second tells how i want

Attached image(s)

  • Attached Image
  • Attached Image

This post has been edited by Mohsin01: 02 April 2015 - 09:22 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1