Re: [PHP] hierarchies

2009-03-27 Thread Jason Pruim



PJ wrote:

I do have a bit of a problem which has not been clearly explained in
the suggestions to my previous posts and that is the question of
hierarchies. I have not yet understood how to include a file anywhere in
a directory tree and have it point to the right file which may be in the
top directory or, most likely, in a /lib/ directory from the file that
is including.
Any suggestions, or should I just make myself small and
wait for the rotten eggs and spoiled tomatoes to come raining down on my
head? :'(

  

Are you talking about having a file structure such as:

/home
/include
/webroot
/-images
/-css
/-java

And you want to include a file from the include folder which is above 
the webroot, so doesn't have access to it?


If that's the case... you just need to set the path such as: 
ini_set(include_path, /home/include);

then in your PHP file you should be able to: include(mysupperfile.php);
and it should work :)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] hierarchies

2009-03-27 Thread PJ
Jason Pruim wrote:


 PJ wrote:
 I do have a bit of a problem which has not been clearly explained in
 the suggestions to my previous posts and that is the question of
 hierarchies. I have not yet understood how to include a file anywhere in
 a directory tree and have it point to the right file which may be in the
 top directory or, most likely, in a /lib/ directory from the file that
 is including.
 Any suggestions, or should I just make myself small and
 wait for the rotten eggs and spoiled tomatoes to come raining down on my
 head? :'(

   
 Are you talking about having a file structure such as:

 /home
 /include
 /webroot
 /-images
 /-css
 /-java

 And you want to include a file from the include folder which is above
 the webroot, so doesn't have access to it?

 If that's the case... you just need to set the path such as:
 ini_set(include_path, /home/include);
 then in your PHP file you should be able to: include(mysupperfile.php);
 and it should work :)


Not quite, but interesting option. This would be fine on my local
intranet, if needed; but I don't think this would be allowed on a
virtual hosted site.

Actually, my problem is to use a header.php (for example) in pages in
the webroot directory or any directory within (or under) webroot:

/  webroot
/site1
   /files
   /images
   /lib
   /more files
   /admin
  /other_files
  /still_others
/site2
/site3
files
files
files...

I have the header.php file in /lib .
If I put include dirname(_FILE_)./lib/header.php; in a file under
/site1, the header is displayed.
If I put the same include statement in a file under /site1/files, the
header is not displayed; if I change the include to
.../../lib/header.php; it then works.
I want to be able to point to the include to the same file in the same
directory without having to change the include directive.

-- 
unheralded genius: A clean desk is the sign of a dull mind. 
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] hierarchies

2009-03-27 Thread Jason Pruim

PJ wrote:

Jason Pruim wrote:
  

PJ wrote:


I do have a bit of a problem which has not been clearly explained in
the suggestions to my previous posts and that is the question of
hierarchies. I have not yet understood how to include a file anywhere in
a directory tree and have it point to the right file which may be in the
top directory or, most likely, in a /lib/ directory from the file that
is including.
Any suggestions, or should I just make myself small and
wait for the rotten eggs and spoiled tomatoes to come raining down on my
head? :'(

  
  

Are you talking about having a file structure such as:

/home
/include
/webroot
/-images
/-css
/-java

And you want to include a file from the include folder which is above
the webroot, so doesn't have access to it?

If that's the case... you just need to set the path such as:
ini_set(include_path, /home/include);
then in your PHP file you should be able to: include(mysupperfile.php);
and it should work :)




Not quite, but interesting option. This would be fine on my local
intranet, if needed; but I don't think this would be allowed on a
virtual hosted site.

Actually, my problem is to use a header.php (for example) in pages in
the webroot directory or any directory within (or under) webroot:

/  webroot
/site1
   /files
   /images
   /lib
   /more files
   /admin
  /other_files
  /still_others
/site2
/site3
files
files
files...

I have the header.php file in /lib .
If I put include dirname(_FILE_)./lib/header.php; in a file under
/site1, the header is displayed.
If I put the same include statement in a file under /site1/files, the
header is not displayed; if I change the include to
.../../lib/header.php; it then works.
I want to be able to point to the include to the same file in the same
directory without having to change the include directive.

  
I actually use that on a shared host... Really depends on the host 
though... My actual file path is something more like:


/home/
   /myusername/
   /include/
   /public_html/  Web root
  /file.php
  /another folder/


So all my files are inside my home folder on the server, but nothing 
outside of public_html is accessible from the web.


As for the rest... I haven't started using dir(__FILE__) stuff yet so I 
won't be any help with that...




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] hierarchies

2009-03-27 Thread Shawn McKenzie
PJ wrote:
 Not quite, but interesting option. This would be fine on my local
 intranet, if needed; but I don't think this would be allowed on a
 virtual hosted site.
 
 Actually, my problem is to use a header.php (for example) in pages in
 the webroot directory or any directory within (or under) webroot:
 
 /  webroot
 /site1
/files
/images
/lib
/more files
/admin
   /other_files
   /still_others
 /site2
 /site3
 files
 files
 files...
 
 I have the header.php file in /lib .
 If I put include dirname(_FILE_)./lib/header.php; in a file under
 /site1, the header is displayed.
 If I put the same include statement in a file under /site1/files, the
 header is not displayed; if I change the include to
 .../../lib/header.php; it then works.
 I want to be able to point to the include to the same file in the same
 directory without having to change the include directive.
 

The problem is with how you are organizing your app.  Includes are
relative to the first file that's loaded, so if the first file that is
loaded is in /site1/files/ then you have to know where /lib/header.php
is from there.

Most people don't load individual files (at least not from different
dirs) as you seem to be doing.  My advice is to always load the same
file first from the root dir and then include your other files.  Then
those files will include header.php relative to the root dir.

*** Example:

(/site1/index.php)
?php
//based upon some criteria
include('files/yourfile.php');
?

(/site1/files/yourfile.php)
?php
include('lib/header.php');
?

*** Better Example:

(/site1/index.php)
?php
include('lib/header.php');
//based upon some criteria
include('files/yourfile.php');
?

(/site1/files/yourfile.php)
?php
//content that is original to this file
?


Above when I say based upon some criteria, it would be something like
this (example only):

switch ($_GET['file']) {
case 'yourfile':
include('files/yourfile.php');
break;

case 'somefile':
include('more_files/somefile.php');
break;
}

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Hierarchies and MySQL with PHP

2004-06-28 Thread Mattias Thorslund
Warren Vail wrote:
I did one once where the key to the table was a string, and the string
contained 1 to n Node Numbers separated by a separator character.
1
1.1
1.1.1
1.2
select data from table where node between (1 and 2)
resulted in an entire limb of the tree being retrieved.  Limitations were
the size of the string, depth of the tree (the string was truncated), and
the number of digits in each node number.  Problem also with ordering node
numbers, node number 1 tended to be followed by node number 10, 11, 12, etc,
then number 2, until I pre-determined the number of leading zeros for each
node.
Not pretty, but it works well for small trees.
Warren Vail
 

Been there, done that, ran into the same limitations :-)
The flat table solution in the article suggested by Marek keeps a 
running display order integer column, updated only when items are 
added (or removed, but that's not strictly necessary if you don't mind 
holes in the sequence).  When inserting a new item, it gets the display 
order value of the parent + 1, and the following items have their 
display order incremented by 1. Simple.  There's also an indentation 
level column, which is simple enough to maintain.

/Mattias
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Hierarchies and MySQL with PHP

2004-06-27 Thread Marek Kilimajer
This should be of your interest:
http://www.evolt.org/article/Four_ways_to_work_with_hierarchical_data/17/4047/
Mattias Thorslund wrote --- napĂ­sal::
Hi,
I wonder what you think are the best (or least worst) strategies to 
store and retrieve hierarchial data (such as a threaded discussion or 
a multi-level menu tree) in MySQL using PHP?

I have been using table structures where each row contains a parent 
reference, such as:

Table Example:
Field namedata type/db flagsComents
=
RowID int unsigned auto_increment not null  (primary key)
ParentRowID   int unsigned  0 (or NULL if at top 
level)
Name  varchar(50)

... which is OK for *defining* the hierarchy.  However, it's a pain to 
retrieve the data so that it can be displayed in a nice threaded/sorted 
way, where children are sorted directly below their parents.  I also 
want the items to be nicely sorted within their own branch, of course.

On MS SQL, I successfully used stored procedures that employ temporary 
tables and while statements and the like.  That method is not available 
in MySQL (yet), so I'll have to do a lot of the manipulation on the web 
server instead, using PHP.

Any suggestions?
/Mattias
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Hierarchies and MySQL with PHP

2004-06-27 Thread Warren Vail
I did one once where the key to the table was a string, and the string
contained 1 to n Node Numbers separated by a separator character.

1
1.1
1.1.1
1.2

select data from table where node between (1 and 2)

resulted in an entire limb of the tree being retrieved.  Limitations were
the size of the string, depth of the tree (the string was truncated), and
the number of digits in each node number.  Problem also with ordering node
numbers, node number 1 tended to be followed by node number 10, 11, 12, etc,
then number 2, until I pre-determined the number of leading zeros for each
node.

Not pretty, but it works well for small trees.

Warren Vail

-Original Message-
From: Mattias Thorslund [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 27, 2004 9:59 AM
To: PHP General Mail List
Subject: [PHP] Hierarchies and MySQL with PHP


Hi,

I wonder what you think are the best (or least worst) strategies to
store and retrieve hierarchial data (such as a threaded discussion or
a multi-level menu tree) in MySQL using PHP?

I have been using table structures where each row contains a parent
reference, such as:

Table Example:

Field namedata type/db flagsComents
=
RowID int unsigned auto_increment not null  (primary key)
ParentRowID   int unsigned  0 (or NULL if at top
level)
Name  varchar(50)


... which is OK for *defining* the hierarchy.  However, it's a pain to
retrieve the data so that it can be displayed in a nice threaded/sorted
way, where children are sorted directly below their parents.  I also
want the items to be nicely sorted within their own branch, of course.

On MS SQL, I successfully used stored procedures that employ temporary
tables and while statements and the like.  That method is not available
in MySQL (yet), so I'll have to do a lot of the manipulation on the web
server instead, using PHP.

Any suggestions?

/Mattias

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Hierarchies and MySQL with PHP

2004-06-27 Thread Mattias Thorslund
Marek Kilimajer wrote:
This should be of your interest:
http://www.evolt.org/article/Four_ways_to_work_with_hierarchical_data/17/4047/ 


Indeed!  The flat table model is simple, efficient and - I think - 
sufficient. Thanks!

I also found this article which explains the fourth method not really 
described above, despite the title:
http://www.sitepoint.com/article/hierarchical-data-database/

That method is a bit more complicated but it also allows you to 
determine the (total) number of child nodes of a node, without an extra 
SQL query.

/Mattias
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Hierarchies

2001-11-28 Thread Dimitris Kossikidis

You can do it only in few lines of code with a recursive function... You
can display full tree structure with unlimited  levels.

Mysql Table  :
cid int,
parent int,
Name varchar

Cid parent  varchar
1   0   A
2   1   C
3   0   B
4   1   D
5   2   E
6   3   F
This should output :

- A
- - C
- - - E
- - D
- B
- - F


  function ShowTree($parent=0,$level=0){
$query=mysql_query(select cid,parent,name from categories where
parent='$parent');
$level++;
while ($row=mysql_fetch_object($query) ){
   $cnt=$row-cid;
   $element[$cnt]['cid']=$row-cid;
   $element[$cnt]['parent']=$row-parent;
   $element[$cnt]['name']=$row-name;
   echo str_repeat('-', $level) .B.$element[$cnt]['name']./B
(level=$level)(counter=$cnt)br;
   ShowTree($element[$cnt]['cid'],$level);
 }
  }

 ShowTree(0,0);

 -Original Message-
 From: MindHunter [mailto:[EMAIL PROTECTED]] 
 Sent: Wednesday, November 28, 2001 9:27 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Hierarchies
 
 
 Hi,
 
 I need to display hierarchies (hierarchical structures).  I 
 have a MYSQL table with data like this:
 
 Node,Parent
 A,
 B,A
 C,A
 D,B
 E,B
 F,D
 G,A
 
 It can go down to 10 levels.
 
 I do not want display one level and then click to display the 
 next, I want to see the entire tree at once, say like this:
 
 A
 ---B
 --D
 -F
 --E
 ---C
 ---G
 
 Any ideas, scripts on how I can do this?  I seems like I have 
 to use a recursive function and /or arrays?
 
 Any help will be appreciated!
 
 Thanks
 MH
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: 
 [EMAIL PROTECTED] To contact the list 
 administrators, e-mail: [EMAIL PROTECTED]
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]