Jump to content

[category] - [sub category]

- - - - -

  • Please log in to reply
4 replies to this topic

#1
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Hi guys

i want show category with sub and sub in <select><option> tags

i have this table
ID int(11)
PARENT int(11)
SUBJECT varchar(255)

i want code for show records in select option tags.

record view

Sub1

  --Parent1

     >>SP1

     >>SP2

  --Parent2

     >>SP1

     >>SP2

  --Parent3

     >>SP1

     >>SP2

Sub2

  --Parent1

     >>SP1

     >>SP2

  --Parent2

     >>SP1

     >>SP2

  --Parent3

     >>SP1

     >>SP2

Sub3

  --Parent1

     >>SP1

     >>SP2

  --Parent2

     >>SP1

     >>SP2

  --Parent3

     >>SP1

     >>SP2


help me please
Thanks

#2
Mark Wylde

Mark Wylde

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
As far as I know you won't get sub-sub categories in an html select tag. You can however have one parent level of categories using the optgroup tag.

For example:
<select>

  <optgroup label="Swedish Cars">

    <option value="volvo">Volvo</option>

    <option value="saab">Saab</option>

  </optgroup>

  <optgroup label="German Cars">

    <option value="mercedes">Mercedes</option>

    <option value="audi">Audi</option>

  </optgroup>

</select>
Source: HTML optgroup tag

You could sort your table by group returning results as such:
item1 - header1
item2 - header1
item3 - header1
item1 - header2
item2 - header2
item3 - header2

Then while you're looping through your results if the header is different from the previous one, add a new optgroup tab. Look at the link I got the source from above and see if you can work it out. Or provide some code you already have and we might be able to have a look at it for you.

#3
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
hey, I need php code for create cat and sub

#4
Mark Wylde

Mark Wylde

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Again, what code do you have at the minute to work with? Have you coded anything as of yet? Do you have a page that is bringing back the results from the database?

#5
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
i want php code for result database

my records:

Sub1

  --Parent1

     >>SP1

     >>SP2

  --Parent2

     >>SP1

     >>SP2

  --Parent3

     >>SP1

     >>SP2

Sub2

  --Parent1

     >>SP1

     >>SP2

  --Parent2

     >>SP1

     >>SP2

  --Parent3

     >>SP1

     >>SP2

Sub3

  --Parent1

     >>SP1

     >>SP2

  --Parent2

     >>SP1

     >>SP2

  --Parent3

     >>SP1

     >>SP2






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users