PHP - Genealogy Tree
Hey guys i need to create a genealogy tree view in PHP and i have no idea on how to get started ... Is there existing class's for that out there? Any recomandations on the "how to"? Maby flash/xml is better? ... I am lost ...
Similar TutorialsHello, I am currently working on a multi level marketing system requiring a lot of special features than the regular. It has 7 different levels with which you have move to the next level as your downlines qualify for the previous levels respectively. I am quite stuck on the tree structure. Here is how the plan details **1st stage** is 3 direct downlines only **2nd stage** 9 people from the direct 3 should qualify for 1st stage making total of 30, that mean 3 from 1st leg,3 from 2nd leg ,3 from 3 leg
**stage 3** ,9 people from the 30 should qualify for 2nd stage and it should fall on the direct 3
I need help with these first three functions and I will work the rest out. Building a separate tree view for each of the stages. Thanks Hi guys I need help writing a php script I have a table 'categories' with fields 'id' 'cat_name' 'parent_id' the 'parent_id' is just an the id field.. I want to create a way to have unlimited sub categories so I can have categorie -> sub-categories categories -> sub-categories -> sub-categories categories -> products Hi, I wrote a piece of code for doing a recursive printing of all the leaf nodes. But it is not moving beyond one or two levels. Here is the code: $root = array( "paa" => array ( "adi1" => array ( "cir1" => array ( "aka", "ra", "vinodh","dkido" ), "cir2" => array ( "muta", "la" ), "cir3" => array ( "ezut", "telAm" ), "cir4" => array ( "ati" ) ), "adi2" => array ( "cir1" => array ( "paka", "vaV" ), "cir2" => array ( "mutaR", "RE" ), "cir3" => array ( "ula", "ku" ) ) ) ); function traverse($ar) { foreach($ar as $key=>$value) { echo "inside loop of ".$key."<br/>"; if(is_array($value)) { return traverse($value); } else { echo $key."==>".$value."<br/>"; } } } traverse($root); The output I get is: inside loop of paa inside loop of adi1 inside loop of cir1 inside loop of 0 0==>aka inside loop of 1 1==>ra inside loop of 2 2==>vinodh inside loop of 3 3==>dkido It does not seem to visit the other nodes. Anything I missed here ? V hi all. I am working on a MLM project in which i have more than 30,000 members followed by the root member,i have to store member automatically in binary tree form like 1 is root 2 is child of 1 3 is child of 1 Then 4 is child of 2 5 is child of 2 and so on ...... i have to design database for that. please help Can somebody please have a look at this. The Problem I am having is that only 1 entry for each month goes into the tree and for the life of me I can't figure out why. Code: [Select] $queryyp = "SELECT YEAR(date) as year, MONTHNAME(date) as month, title FROM monsterpost ORDER BY date DESC"; // query to get the rows you want in the order that you want them, with the year and monthname specifically selected as well $resultyp = mysql_query($queryyp); $last_heading = null; // remember the last heading (initialize to null) while($rowyp = mysql_fetch_assoc($resultyp)){ $new_heading = $rowyp['year']; // get the column in the data that represents the heading $new_subheading = $rowyp['month']; // get the column in the data that represents the subheading if($last_heading != $new_heading){ // heading changed or is the first one $last_heading = $new_heading; // remember the new heading $last_subheading = null; // (re)initialize the subheading // start a new section, output the heading here... echo "<ol class=\"tree\"><li><label for=\"folder1\">{$rowyp['year']}</label> <input type=\"checkbox\" id=\"folder1\" /></li></ol>"; } // subheading under each heading if($last_subheading != $new_subheading){ // subheading changed or is the first one $last_subheading = $new_subheading; // remember the new subheading // start a new section, output the subheading here... echo "<ol><li><label for=\"subfolder1\">{$rowyp['month']}</label> <input type=\"checkbox\" id=\"subfolder1\" />"; } // output each piece of data under a heading here... echo "<ol><li class=\"file\">{$rowyp['title']}</li></ol></li></ol></li></ol>"; } This is my first try to display binary tree so please go easy on me. I am trying to display binary tree using array. The values are stored in mysql. Structure of mysql- Code: [Select] CREATE TABLE IF NOT EXISTS `tree` ( `parent` int(7) NOT NULL, `rchild` int(7) NOT NULL, `lchild` int(7) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Display should look like Code: [Select] 1 ______|______ | | 2 3 ______|______ | | 4 5 My Code till now- Code: [Select] <?php include 'connection.php'; $rsearch = "SELECT rchild FROM tree WHERE parent='".$parent."'"; $lsearch = "SELECT lchild FROM tree WHERE parent='".$parent."'"; $rexec = mysql_query($rsearch); $lexec = mysql_query($lsearch); while($rrow = mysql_fetch_assoc($rexec)) // Putting right branch in an array first { $rtree[$i][0] = $rrow['parent'] ; $rtree[$i][1] = $rrow['lchild'] ; $rtree[$i][2] = $rrow['rchild'] ; $i++; } while($lrow = mysql_fetch_assoc($lexec)) // Putting left branch in an array { $ltree[$j][0] = $lrow['parent'] ; $ltree[$j][1] = $lrow['lchild'] ; $ltree[$j][2] = $lrow['rchild'] ; $j++; } function displaytree($parent,$array) { // Im stuck here. Can someone please help me with it } ?> I am stuck at displaying the tree function. Can someone please point me in the right direction ? Hey guys, I have a bunch of categories and products in a tree format. For several reasons I need to restructure them from the tree format into a flattened format. I have 2 arrays, one full of categories, the other products. Each category and product has an ID, and a reference to it's parent's ID. The top level categories reference to 0. What I need is to have the categories output like thus: Top Level Categories: Category 1 Category 2 Category 1 Sub category 1 Sub category 2 Category 2 Sub category 3 Sub category 4 Sub category 1 Product 1 Product 2 Sub category 2 Product 3 Product 4 Sub category 3 Product 5 Product 6 Sub category 4 Product 7 Product 8 There could be an unlimited number of sub categories within categories before we get to products, so this needs to be done through a function, however I cannot for the life of me think how to do this. Initially I thought about using 2 arrays, a buffer of categories outputted, and a queue of categories to be outputted, but quickly realised that when I go more than 2 layers deep I can't keep track of the queue's properly. Hey guys, i am a college student and working on a project of mlm ad want to display the binary income tree,and also calculate the income that is given to each node. Please see the attachments for the binary tree structure and database table structure. Thanks. [attachment deleted by admin] Hello everybody, i am working on n level category tree structure, for your information the category tree structure image is attached with this post. Let's consider, each of the category have hundreds( n level ) of category in each, i want to traverse each category without using recursive functions, reason being recursive functions are very slow, is there any way to do this?? Thanks, phpeid I am trying to display binary tree level wise. Breadth-first tree traversal can be used in it.Can anyone point me towards its logic or point me towards a good tutorial. I am trying to count left node of a binary tree.I made a function but my result is always 3 . Code:- Code: [Select] <?php include'config.php'; // Connect database function leftcount($node) //Function to calculate leftcount { $sql = "SELECT lchild,rchild FROM tree WHERE parent = '$node'"; $execsql = mysql_query($sql); $array = mysql_fetch_array($execsql); if(!empty($array['lchild'])) { $count++; leftcount($array['lchild']); } if(!empty($array['rchild'])) { $count++; leftcount($array['rchild']); } $totalcount = 1 + $count; return $totalcount; } $parent = "2"; $left = leftcount($parent); echo $left; ?> Can someone please point the error in my logic ? I searched google but i only got scripts with classes and i don't want to use classes. Hello, I am using Fancytree, I want to generate a file / folder tree but excluding all folders that are not from the current user.
Example: I want to create a tree structure with the user "Peter"
[Tree]
I have several problems: Here is my code: <?php $name_user = 'Peter'; // actualy not user :-( print_r(listFolders()); function listFolders($dir = __DIR__ . '/datausers') { $dh = scandir($dir); $name_user = "Peter"; $return = []; if (strpos($dir, "/datausers/PERSONNAL") !== false){ // PERSONNAL found ! if ($dir === __DIR__ . '/datausers/PERSONNAL') { print_r($dir); echo '</br>'; foreach ($dh as $item) { if ($item != '.' && $item != '..') { if (is_dir($dir . '/' . $item)) { // it's a folder $return[] = array( 'title' => $item, 'folder' => true, 'expanded'=> true, 'children' => listFolders($dir . '/' . $item, $key) ); } else { // it's a file $return[] = [ 'title' => $item, ]; } } } } if (strpos($dir, "/datausers/PERSONNAL/" . $name_user) !== false){ // Peter found print_r($dir); echo '</br>'; foreach ($dh as $item) { if ($item != '.' && $item != '..') { if (is_dir($dir . '/' . $item)) { // it's a folder $return[] = array( 'title' => $item, 'folder' => true, 'expanded'=> true, 'children' => listFolders($dir . '/' . $item, $key) ); } else { // it's a file $return[] = [ 'title' => $item, ]; } } } } } else { print_r($dir); echo '</br>'; foreach ($dh as $item) { if ($item != '.' && $item != '..') { if (is_dir($dir . '/' . $item)) { // it's a folder $return[] = array( 'title' => $item, 'folder' => true, 'expanded'=> true, 'children' => listFolders($dir . '/' . $item, $key) ); } else { // it's a file $return[] = [ 'title' => $item, ]; } } } } return $return; } ?> Please help me I'm desperate ... Edited July 6 by ScottMeyerhi guys. i want to implement a referral system. a member can only refer using a form in the memebers area. on the referral form, i have a hidden field which is his referral id and a unique code (md5 generated link) and a field for the email address he wants to refer. once he sends the mail, a referal link (md5 generated, for uniqueness and to curb cheating) is sent to the email so that once he clicks, it takes him/her to the registration area. on my database table referrer_uid - the unique id of person referring someone referred_uid - the unique id of person being referred ref_code - the md5 generated code which is used on the link sent referred_email - the email address of the person being referred status - once a member sends a refer link, status is set to Referal sent date_referred - the date the refering took place date_accepted - the day the referred was accepted (i dont want this to change on clicking a referal link or registration cos not everyone gets accepted to avoid spurious referals) my question is how do i create a traversal tree with this. i read about traversal tree on sitepoint but when i tried to implement the examples, it didnt work for me and i noticed it was an old post. note: i intend giving points based on the child/tree and it could be as deep as possible. also if my method is wrong, ideas are higly appreciated. thanks Evening everyone and Merry X-Mas (Happy Holidays) or whatever fits you best.... I have been trying over and over for about 12 hours to figure out how to get data from a specific JSON response and assign the specific values to a new array key/value pair. The various ways I have tried to figure this out are numerous so i'm going to avoid the runnig list of "I trieid this...and this...and this... etc etc." just understand I have reached a dead end point where I need help badly.
Here is what our end goal is:
"The company" is a "service industry" provider (plumbing, electrical etc. etc.) who wants to dispatch its technicians to new jobs based on which technician has the shortest travel time from any existing address where they already have a scheduled appointment that day and has available time in there schedule. Thus the dispatching system when a new service call is entered is going to give "recommended" technicians (up to 4) to be assigned the new service call based on the above mentioned criteria. (Efficient routing to save company gas cost)
1.) We have a "New service" street address assigned to the $to variable: $to = "4813 River Basin Dr S, Jacksonville FL 32207"; 2.) We will have "records" array which containes a series of records, each record consists of a ticket# a technician id# and a street address: $records = array( array("DV1012","30453423","9890 Hutchinson Park Dr Jacksonville, FL 32225"), array("DB3434","30404041","821 Orange Ave Crescent City, FL 32112"), array("DB3434","30605060","1972 Wells Road, Orange Park FL 32073"), array("DB4578","30605060","2 Independent Drive, Jacksonville FL 32202"), array("DB7841","30605060","5000 Norwood Avenue, Jacksonville FL 32208"), array("DB3235","30605060","9501 Arlington Expressway, Jacksonville FL 32225"), array("DB7894","30605060","Massey Avenue, Jacksonville, FL 32227"), array("DB2020","30121212","11200 Central Pkwy Jacksonville, FL 32224") ); 3.) We are going to prepare the records array for submission to Google's Distance Matrix API by URL encoding each array value into a single variable and then submit it: foreach ($records as $key => $value) {$from = $from.urlencode($value[2])."|";} $to = urlencode($to); $data = file_get_contents("//maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=en-EN&units=imperial&mode=driving&sensor=false"); $res=json_decode($data) or die("Error: Cannot read object"); You may look at the ACTUAL live Google response from this he http://tiny.cc/i6eerx (We have applied <pre> and var_dump($res) to the output) We are looking to get the following information back: The distance and travel time between the "New Service" address ($to) and each of the address' in the $records array ($from), now once that information is returned from Google (JSON response) we need to parse the response and narrow it down to 4 or less (Based on the 4 lowest drive times) to form a new array which ends like this: $results = array( array("DV1012","30453423","2.3 Miles","8 mins"), array("DB3434","30404041","2.8 Miles","9 mins"), array("DB3434","30605060","4.6 Miles","13.8 mins"), array("DB4578","30605060","5.7 Miles","15.2 min") ); OUR PROBLEM: Everything up until the the Google API response is fine, but iterating over the multidimensional arrays within multidimensional arrays of the JSON response is just not coming together in my head (or 2 dozen code attempts). I am able to ECHO an individual value like ( echo $res->rows[0]->elements[0]->distance->text; ) but this has no value for the end result i need to get to. My last thoughts and efforts was that that I was going to have to embed foreach statements within foreach statements to drill down through the various arrays but that hasn't worked very well and it seems like it shouldn't be how it has to be done. I would appreciate any help in showing me how the iteration code should be written and any explanation about the code so i can wrap my head around it. Hello I have an array that I would like to display as a family tree... and am looking for an example script that will allow me to do this. I want to be able to create X number of generations and fill the boxes with data from my array.... So, if I want 5 generations I want to generate a tree with 63 elements or boxes Any help would be appreciated Thanks Hello my good people
I'm doing a content manager system in PHP and mySQLi, following a serie of video tutorials.
But in my project I am using a tree menu.
In the front office all works smoothly (the tree menu displays all results - menu and submenus - and each button carries the information of the respective page). Hello all, I'm trying to change the way the output look like from Recursion instead of it looking like this and make it look like this here is my code Code: [Select] <?php $user = $_GET['id']; echo '<hr>'; function display_mptt($user) { global $db; $id = $_GET['id']; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id= ".$id.""; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Your Tree</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE `left` BETWEEN ".$row2['left']." AND ".$row2['right']." ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)) { // only check stack if there is one if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title // add this node to the stack $right[] = $row['right']; } echo str_repeat(' ',count($right)).$row['title']."<br>"; } display_mptt(1); ?> I'm trying to build a tree to display product groups, but I can't achieve what I want. There is a hierarchy for the tree which I need to follow:
1H I want to list all the categories (1H) with its subcategories(1HS), and it's subcategories (1HSMP). This is the code I'm currently using: <ul> <?php //Here we fetch category $categories_list = array(); if($stmt = $conn -> prepare("SELECT a.category, a.subcategory, a.subcategory1, a.category_description, a.subcategory_description, a.subcategory_description1, SUM(nsq.sales_amount) AS sales, SUM(nsq.sales_amount+nsq.cost_amount) AS RUC FROM dpb.articles a LEFT JOIN dpb.nav_sales_qty nsq ON nsq.article_no = a.article_no WHERE nsq.entry_type_desc = 'Prodaja' GROUP BY a.subcategory1")) { $stmt -> execute(); $stmt -> store_result(); $stmt -> bind_result($category, $subcategory, $subcategory1, $category_description, $subcategory_description, $subcategory_description1, $total_sales, $total_profit); while($stmt -> fetch()) { $categories_list[] = array('category' => $category, 'subcategory' => $subcategory, 'subcategory1' => $subcategory1, 'category_description' => $category_description, 'subcategory_description' => $subcategory_description, 'subcategory_description1' => $subcategory_description1, 'total_profit' => $total_profit, 'total_sales' => $total_sales); } $stmt -> close(); } foreach($categories_list as $key => $value) { ?> <li><?php echo $value['category'].' - '.$value['category_description']; ?> <ul> <?php //Here we filter subcategory if(strpos($value['subcategory'], $value['category']) === 0) { //Iterate over subcategory foreach ($value as $key2 => $value2) { debugVar($value2); ?> <li data-jstree='{"opened":true}'><?php echo $value2['subcategory'] . ' - ' . $value2['subcategory_description']; ?> <ul> <?php //Here we filter subcategory2 if (strpos($value['subcategory1'], $value['subcategory']) !== false) { ?> <li data-jstree='{"type":"file"}'> <?php echo $value['subcategory1']; ?> </li> <?php //Here we close subcategory1 if statement } ?> </ul> </li> <?php //Here we close subcategory if statement } } ?> </ul> </li> <?php //Close foreach loop } ?> </ul> The result I'm getting is attached in the photo, and it's not what I want! The result I need is the following: I find a category (1H), and then I find all of its subcategories which are 1H% (all that start with 1H) and display them bellow 1H. Then I iterate over all of these subcategories (example 1HS%, 1HP%, 1HRD%) and I find all of their subcategories which are starting with (1HS, 1HP, 1HRD) and display them. Example:
1H Can you please help me how to achieve that? I spent a lot of time, and I can't get the proper result.
Hi everyone, I have a file filled with categories (about 100K or so lines), each one by indentation (for illustration purposes, I added + instead). Quote Root + Category ++ File 1 +++ Sub Cat ++++ File 4 ++++ File 5 ++ File 2 + Category 2 ++ SubCategory 1 +++ File 1 ++ SubCategory 2 What am trying to is upload this file, and have it input into my table so jsTree can render it correctly. It correctly inserts most of the lines, but starts to get confused when reverting back to previous lines (in the above example, it will insert up to file 5 correctly, then get lost on the left/right on File 2.) Am using jsTree's create_node, but not sure why the render is failing? My (rather brute-force) upload script is below: Code: [Select] $dataFile = fopen($file_dir . basename($_FILES['uploaded']['name']), "rb"); while (!feof($dataFile)) { $lines = array(); while (($line = fgets($dataFile)) !== false) { array_push($lines, rtrim($line)); } $count = count($lines); $res = preg_replace('/\t/i', "|", $lines); $final = preg_replace("/\s(\W)[^\w]/i", "|", $res); $i = 0; foreach($final as $string) { //$parent_id = $delimiter_count - 1; $delimiter_count = substr_count($string, '|'); //level $left = $i + 1; $right = $left + 1; preg_match("/(\|+)(\w.+)/i", $string, $match); if(isset($match[2])) { /* even this doesn't work, if I directly inject it into the tree $insert = $keysdb->query("INSERT INTO tree (`parent_id`, `position`, `left`, `right`, `level`, `title`, `type`, `post_syn_epon`, `post_author_id`) VALUES('$delimiter_count',0,'$left','$right','$delimiter_count','$match[2]','default','$match[2], ','user_id')"); */ $jstree->create_node(array( "id" => "$delimiter_count", "position" => 0, "title" => "$match[2]", "type" => "default" )); if(!$insert) { print "Failed!" . $keysdb->error; } } $i++; } } // all done close the file fclose($dataFile); |