Log in

View Full Version : Multi level categories



sami
05-01-2007, 09:23 PM
Hi,

I cannot seem to find any articles about multi level categories and sub categories in php.

I only know how to create a 1 level categories only. Does anyone know how or could point me into the right direction?
thanks in advance.
Sami

Twey
05-01-2007, 10:04 PM
Categories of what?

A filesystem setup will work, as will a tree setup with a database, where you have a table of "folders," each of which except the root has exactly one parent referenced.

sami
05-02-2007, 01:51 PM
I meant like using mkdir() to make a dir and add subdir into it.

I think it is something like this:

Top Level
- Sub1
- Sub1_1
- Sub1_2
- Sub2
- Sub3

Twey
05-02-2007, 05:32 PM
mkdir (http://www.php.net/mkdir)('dir/subdir');

sami
05-02-2007, 09:12 PM
I'm learning how to explain this.

Just say that I a top level category or directory and I wanted to create very very deep into that category.

Like this...

Top Level > x > xx> and etc... nn>vv

So how would you create that from a php script. thanks.

djr33
05-02-2007, 10:30 PM
I'm so confused about even the general idea of what you are doing.

you're making folders on the site, right?

So... mkdir('a/b/c/d/e/.../z/whatever'); ?

Twey
05-03-2007, 10:35 AM
With PHP5, you can:
mkdir('x/xx/blah/nn/vv', 0777, true);However, in earlier versions you'd have to do it one at a time:
$pathname = 'x/xx/blah/nn/vv';
$dirs = explode('/', $pathname);
foreach($dirs as $i => $dir)
mkdir(implode('/', array_slice($dirs, 0, $i + 1)));

djr33
05-03-2007, 11:27 AM
Oh, I didn't think of that. I was just accessing the folder, forgetting that I was creating it as that function. How silly.