问题:
如何将PHP递归函数转换或写入mysql递归存储过程?
问题:
下面的php递归占用了太多的加载时间来获取父子节点。所以请告诉我如何通过在mysql中编写存储过程来提高性能。
我的PHP代码:
<?php
function display_children($parent, $level)
{
$con=mysqli_connect("localhost","root","","testing_purpose");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT a.parent,a.id, a.label, a.link, Deriv1.Count FROM `menu` a LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `menu` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" . $parent);
echo "<ul class='menu'>";
while ($row = mysqli_fetch_assoc($result))
{
if ($row['Count'] > 0)
{
echo "<li style='display:none;' id='" . $row['parent'] . "' onclick=id_func('" . $row['id'] . "')>" . $row['label'];
display_children($row['id'], $level + 1);
echo "</li>";
}
elseif ($row['Count']==0)
{
echo "<li style='display:none;' id='" . $row['parent'] . "' onclick=id_func('" . $row['id'] . "')>" . $row['label'] . "</li>";
} else;
}
echo "</ul>";
mysqli_close($con);
}
display_children(0,1);
?>
注意:
我是mysql存储过程的初学者