You are here: Help with PHP, GraphViz and multidemnsional arrays (oh and nested set data) :) « All PHP « IT news, forums, messages
Help with PHP, GraphViz and multidemnsional arrays (oh and nested set data) :)

Posted by HawkEye on 06/25/07 21:01

Hi,

Wonder if anyone can help? I have a nested set database that I need to
extract into GraphViz format ("key 1" -> "subkey1" , "key 1" ->
"subkey2" , "subkey2" -> "subsubkey" etc.)

I'm struggling with getting the data into the format. I have extracted
it into two forms so far as I'm not sure which is easiest to use. I
have one long string for each leaf node and I have a multidmensional
array. Trouble is these contain 'duplicates' that make GraphViz draw
extra lines.

Below is my current code, the output I have and the way I need it if
anyone can suggest how I do it.

Oh I should mention that pear has a class that supposedly does this but
I can't install pear on the server :(

<?
$leaf = array();
$cross = array();
$full = array();
$string = "";
$sql = "SELECT position FROM org_cht WHERE rgt = lft + 1";
$res = mysql_query($sql);

while($row = mysql_fetch_array($res)){
array_push($leaf,$row[position]);
}

foreach ($leaf as $value){
$sql2 = "SELECT parent.position FROM org_cht AS node, org_cht AS parent
WHERE node.lft
BETWEEN parent.lft AND parent.rgt AND node.position = '$value' ORDER BY
parent.lft;";

$res2 = mysql_query($sql2);

while($a_row = mysql_fetch_array($res2)){
$string .= '"'.$a_row[position].'" ->';
array_push($cross,$a_row[position]);
}
array_push($full,$cross);
$string = substr($string,0,-2). "<br>";
$cross = array();

}
?>

String output

"Tim Allen" ->"Dave Barrigan" ->"Paul Biltcliffe"
"Tim Allen" ->"Dave Barrigan" ->"Neil Williams"
"Tim Allen" ->"Gary Hallam" ->"Lee Walker"

Array output

[0] => Array
(
[0] => Tim Allen
[1] => Dave Barrigan
[2] => Paul Biltcliffe
)

[1] => Array
(
[0] => Tim Allen
[1] => Dave Barrigan
[2] => Neil Williams
)

[2] => Array
(
[0] => Tim Allen
[1] => Gary Hallam
[2] => Lee Walker
)

Req'd Format

"5th Edition" -> "6th Edition";
"5th Edition" -> "PWB 1.0";
"6th Edition" -> "LSX";
"6th Edition" -> "1 BSD";
"6th Edition" -> "Mini Unix";
"6th Edition" -> "Wollongong";
"6th Edition" -> "Interdata";
"Interdata" -> "Unix/TS 3.0";


Thanks for any help

Neil

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация