在PHP中创建有向图

在PHP中创建有向图,php,mysql,matrix,directed-graph,Php,Mysql,Matrix,Directed Graph,我正在尝试用php实现一个简单的代码,其中我必须从sql数据库创建一个有向图。我只需要以有向图的形式表示E-R图连接。有人能帮我吗? 这是我的初学者代码。此代码尚未运行。建议即兴表演 这段代码主要是试图创建一个示例图 <?php require_once 'Structures/Graph.php';` $directedGraph =& new Structures_Graph(true); $nonDirectedGraph =& new Structures_Gra

我正在尝试用php实现一个简单的代码,其中我必须从sql数据库创建一个有向图。我只需要以有向图的形式表示E-R图连接。有人能帮我吗? 这是我的初学者代码。此代码尚未运行。建议即兴表演 这段代码主要是试图创建一个示例图

<?php
require_once 'Structures/Graph.php';`

$directedGraph =& new Structures_Graph(true);
$nonDirectedGraph =& new Structures_Graph(false);

require_once 'Structures/Graph/Node.php';

$nodeOne =& new Structures_Graph_Node();
$nodeTwo =& new Structures_Graph_Node();
$nodeThree =& new Structures_Graph_Node();
$directedGraph->addNode();
$directedGraph->addNode();
$directedGraph->addNode();

$nodeOne->connectTo($nodeTwo);
$nodeOne->connectTo($nodeThree);

$nodeOne->setData("Node One's Data is a String");
$nodeTwo->setData(1976);
$nodeThree->setData('Some other string');

print("NodeTwo's Data is an integer: " . $nodeTwo->getData());

$nodeOne->setMetadata('example key', "Node One's Sample Metadata");
print("Metadata stored under key 'example key' in node one: " . $nodeOne->getMetadata('example key'));
$nodeOne->unsetMetadata('example key');

// Nodes are able to calculate their indegree and outdegree
print("NodeOne's inDegree: " . $nodeOne->inDegree());
print("NodeOne's outDegree: " . $nodeOne->outDegree());

// and naturally, nodes can report on their arcs
$arcs = $nodeOne->getNeighbours();
for ($i=0;$i<sizeof($arcs);$i++) {
    print("NodeOne has an arc to " . $arcs[$i]->getData());
}
?>
.

欢迎来到堆栈溢出!请四处看看,特别是通读一下这本书?和?什么是“不工作”?不工作既不是错误信息也不是问题描述。请提供一个失败的例子,以及您希望得到的帮助。此外,它还将有助于显示您的SQL表结构——如果这有缺陷,那么您在PHP中编写的任何内容都需要重新思考。问题解决了。谢谢你的关心。