7, September 2008

is this inheritance? - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: is this inheritance?
« previous next »
Pages: [1] Print

Author Topic: is this inheritance?  (Read 1230 times)
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« on: Jun 26, 2006, 01:03:31 PM »

Hello,

I like to start a new project where I need to loop through several levels to create sub items (line a xml parser).

Now I'm looking for some information, I know that this kind of technique is often used in OOP but I forgot the name of this pattern (is this a pattern?). Maybe someone can tell how is this called?



Last blog : Is your website is down? Know before your visitors do!
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8037
41179 credits
Members referred : 3



« Reply #1 on: Jun 26, 2006, 01:09:40 PM »

You mean something with category hierarhy?

If yes, you want to have infinite number of sub items or a specific number of levels?

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Jun 26, 2006, 01:40:41 PM »

You mean something with category hierarhy?

If yes, you want to have infinite number of sub items or a specific number of levels?
yes, I want to create a class for a dynamic folded menu


Last blog : Is your website is down? Know before your visitors do!
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8037
41179 credits
Members referred : 3



« Reply #3 on: Jun 26, 2006, 01:50:49 PM »

I use this technique :

First you have a table with id, path where path is the path to reach the item.

For example this should be a tree :

id -> 1 , path -> 0
(parent of 1:)
id -> 2, path ->0,1
(parent of 2 Smiley
id-> 3, path 0,1,2

etc.

Then I use a function like this :

Code:
<?php
$ar 
= array();
while(
$record mysql_fetch_array$res ))
{
     
$s="";
     foreach (
explode(",",$record['path']) as $i)
     {
      
$s.= "[$i]";
     }
     
$s.= "[".$record[0]."]";
     
$u "\$ar".$s."[name]= 'whatever you want here';";
     eval(
$u);
}

function 
re($ar,$d=0)

 if (
$ar[name]) {
 
$v=array_shift($ar);
        if(
$v!="")
             echo 
$v;
}

foreach(
$ar as $i=>$v)
 
re($v,($d+1));

?>


It is a difficult to understand code fragment, hope you can make it work Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Jun 26, 2006, 02:18:47 PM »

I have used this kind function before, but this time I want to create OOP version, I read something about but I forgot where...



Last blog : Is your website is down? Know before your visitors do!
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8037
41179 credits
Members referred : 3



« Reply #5 on: Jun 26, 2006, 02:21:55 PM »

It seems that this is not the perfect day to remember....

I remember an XML parser class that used a simmilar model, I will try to search my libraries if it is saved somewhere Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: Jun 26, 2006, 02:53:27 PM »

It seems that this is not the perfect day to remember....

I remember an XML parser class that used a simmilar model, I will try to search my libraries if it is saved somewhere Smiley
Thank, you but I don't need the code, what I wan't is learn and understand Cheesy

I thought there is a special name for this pattern...


Last blog : Is your website is down? Know before your visitors do!
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Jun 26, 2006, 03:34:36 PM »



Last blog : Is your website is down? Know before your visitors do!
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8037
41179 credits
Members referred : 3



« Reply #8 on: Jun 26, 2006, 03:46:39 PM »

Wow, interesting tutorial.

Maybe we should invite this guy to the forum Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Jun 26, 2006, 03:52:42 PM »

Wow, interesting tutorial.

Maybe we should invite this guy to the forum Smiley
Harry Fuecks? I think he is too busy and I think as an author for sitepoint he has to join the sitepoint forums first...

lol


Last blog : Is your website is down? Know before your visitors do!
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #10 on: Jun 27, 2006, 06:03:58 PM »

Quote
I remember an XML parser class that used a simmilar model, I will try to search my libraries if it is saved somewhere...

If you have the time, please post it here ( I'm becomming crazy)  Huh


Last blog : Is your website is down? Know before your visitors do!
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8037
41179 credits
Members referred : 3



« Reply #11 on: Jun 28, 2006, 10:30:08 AM »

I thought you solve that problem.

I will look again and will let you know.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #12 on: Jun 28, 2006, 10:33:44 AM »

I thought you solve that problem.

I will look again and will let you know.

thank you, in the meantime I try it while using mysql record sets and arrays (like your first suggestion)


Last blog : Is your website is down? Know before your visitors do!
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=3029
Tags : forums tutorials mysql xml oop Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: is this inheritance?
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Sep 07, 2008, 12:21:00 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 36.301
Total Topics: 7.479
Total Members: 3.904
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: Brandon

20 Guests, 4 Users online :

11 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.