Seems like there is a flurry of database questions today - most of which aren't really perl issues at all...

To somewhat answer the question - this known as a "master-detail" problem in SQL. To achieve what you want you need to think of the database, and of how the various items in it relate to each other.

If you want maximum flexibility you could do something like this:

create table category ( id numeric(9,0) -- autoincrement , parent_id numeric(9,0) null , name varchar(30) , level int -- might not be needed) , ... other columns )
Note - I don't know what the correct syntax for an auto-increment column is in MySQL...

Anyway - now you have a table that can represent any depth of category nesting.
The downside is that getting the full data in the right order can become an "interesting" exercise.

The table above is just an idea to get you thinking - not necessarily the correct solution to your problem.

Michael


In reply to Re: Pulling out information for MySQL by mpeppler
in thread Pulling out information for MySQL by andrew

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.