Open Source & Stuff  
  |     Main Site     |      Forum     |     Contact     |
Ajax Linked Select boxes :  forum.Salix.gr forum.Salix.gr
Comments, questions, usage, bugs. 
Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
messagehelp: tree in child listbox
Posted by: meisaputra (IP Logged)
Date: September 25, 2007 01:23PM

dear panos,

At this time, we can see only plain data list in the parent and child select list box. Now, I need your help to modificate the way displaying child of items in select listbox.

in example, there are 2 select boxes. first company listbox and second organization is tree structure of the parent listbox (company list).

organization tree structure can we see like in the mysql article [dev.mysql.com]
there are script which can we adopt to create list with some SPACE (&nbsp) for the prefix or the option list items.

see these sample:

company list table (as parent):

abc corporation
cde company
efg inc.
ghi inc.


then the structure org as second list (child):

abc corporation:

structure 1
--structure 1.1
----structure 1.1.1
--structure 1.2
----structure 1.2.1
----structure 1.2.2


cde company:

structure 2
--structure 2.1
----structure 2.1.1
--structure 2.2
----structure 2.2.1
----structure 2.2.2

and so on...

my point is, i need to display child as tree list box.
where is the part I should to change to?
i think, it is better to have a paramater for displaying listbox tree or plain form.

well, i hope u or somebody can send me a modification.
thank u very much.



Edited 1 time(s). Last edit at 09/25/2007 01:27PM by meisaputra.

messageRe: help: tree in child listbox
Posted by: panos (IP Logged)
Date: September 25, 2007 02:44PM

Interesting.....

let me propose something
if can give me a php function that collects data for selected id from tree structure table like

id | description | level

i will add option to lsb to show it smiling smiley

messageRe: help: tree in child listbox
Posted by: meisaputra (IP Logged)
Date: September 25, 2007 03:08PM

this is the function named dbtree_listbox (i use adodb to execute query)

//
// start function
//
function dbtree_listbox($table_name, $key, $value, $condition, $selected_key = 0) {
global $db;

$sql = "SELECT node.$key, CONCAT( REPEAT( '   ', (COUNT(parent.$value) - 1) ), node.$value) AS name ";
$sql .= "FROM $table_name AS node, ";
$sql .= "$table_name AS parent ";
$sql .= "WHERE 1 ";
$sql .= "AND node.lft BETWEEN parent.lft AND parent.rgt ";
if (strlen($condition) > 0) {
$sql .= "AND $condition ";
}
$sql .= "GROUP BY node.name ";
$sql .= "ORDER BY node.lft ";
print $sql;
if (!$r_sql = $db->Execute($sql)) {
print $db->ErrorNo() . $db->ErrorMsg();
exit;
}
if ($r_sql->RecordCount() > 0) {
$selected = "";
while (!$r_sql->EOF) {
$selected = ($r_sql->fields[$key] == $selected_key) ? " SELECTED" : "";
print "<option value=\"".$r_sql->fields[$key]."\"$selected>".$r_sql->fields[$value]."</option>\n";
$r_sql->MoveNext();
}
}
}

//
// end function
//


this is the table group strusture:

CREATE TABLE /*!32312 IF NOT EXISTS*/ `groups` (
`company_id` int(11) NOT NULL,
`name` varchar(30) NOT NULL,
`lft` int(11) NOT NULL,
`rgt` int(11) NOT NULL,
`id` int(11) NOT NULL auto_increment,
PRIMARY KEY (`id`),
UNIQUE KEY `company` (`company_id`,`lft`,`rgt`)
) ENGINE=MyISAM AUTO_INCREMENT=22 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;


and this is the samples content of the group table:

INSERT INTO `groups` (`company_id`, `name`, `lft`, `rgt`, `id`) VALUES
(10,'one',1,12,1),
(10,'one.one',2,7,2),
(10,'one.one.one',3,6,3),
(10,'one.one.one.one',4,5,4),
(10,'one.two',8,11,5),
(10,'one.two.one',9,10,6),
(2,'one',1,12,7),
(2,'one.one',2,3,8),
(2,'one.one',4,9,9),
(2,'three.one',10,11,10),
(2,'two.one.one',5,6,11),
(2,'two.two.one',7,8,12),
(1,'aaaa',1,18,13),
(1,'bbbbb',2,17,14),
(1,'cccc',3,8,15),
(1,'dddd',9,14,16),
(1,'eeee',15,16,17),
(1,'ffff',4,5,18),
(1,'gggg',6,7,19),
(1,'hhhh',10,11,20),
(1,'iiiii',12,13,21);


i have doing some review, maybe we need little modif in sc_select_ajax_handler.php but, i don't know where to put the parameter if we need plain/tree form in the list.

regard.
rms

messageRe: help: tree in child listbox
Posted by: panos (IP Logged)
Date: September 25, 2007 03:25PM

cooool
you were ready for that smiling smiley

give me little time to integrate

messageRe: help: tree in child listbox
Posted by: panos (IP Logged)
Date: September 25, 2007 03:39PM

Question:

parameters:
$table_name = 'groups'
$key = 'id'
$value = 'name'
$condition = 'company_id=10'
$selected_key = ?

correct?



Edited 1 time(s). Last edit at 09/25/2007 04:13PM by panos.

messageRe: help: tree in child listbox
Posted by: panos (IP Logged)
Date: September 25, 2007 06:21PM

still some problems but almost there smiling smiley

messageRe: help: tree in child listbox
Posted by: meisaputra (IP Logged)
Date: September 26, 2007 05:23AM

absolutely right. keep going...

messageRe: help: tree in child listbox
Posted by: meisaputra (IP Logged)
Date: September 26, 2007 01:30PM

hi panos,

i don't want to rush you, but... is there any progress?
smiling smiley

thank before.

messageRe: help: tree in child listbox
Posted by: panos (IP Logged)
Date: September 26, 2007 02:09PM

Take a look at [www.salix.gr]

winking smiley

want it?


download this [www.salix.gr] and please test

messageRe: help: tree in child listbox
Posted by: meisaputra (IP Logged)
Date: September 27, 2007 06:40AM

Thats what I want!

But I need little modification in sc_classes.php in line 487.

$list = $this->dbtree_listbox(
$this->select_boxes[$box_name]['table_name'],
$this->select_boxes[$box_name]['key_field'],
$this->select_boxes[$box_name]['text_field'],
"node.$link_field =$link_field_selected AND parent.$link_field =$link_field_selected" // modif this line
);

because in the groups table hold multi org structure for multi company, so I need condition "parent.$link_field =$link_field_selected"

Thanks panos. Great job smiling smiley

-ms-

messageRe: help: tree in child listbox
Posted by: panos (IP Logged)
Date: September 27, 2007 08:54AM

can you please do me a favor?
can you mail me a dump of your real data so i can play with them smiling smiley
no worries i will keep them private winking smiley



Sorry, only registered users may post in this forum.

All Rights Reserved 2006 Salix.gr  |  Design by Ades Design |  Hosting by e-emporio |  forum.Salix.gr powered by Phorum