$link = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
mysql_select_db('system_db') or die('Could not select database');
include'config.php'; // Connect database
function leftcount($node) //Function to calculate leftcount
{
$sql = "SELECT lchild,rchild FROM tree WHERE parent = 'NULL'";
$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;
This post has been edited by CTphpnwb: 03 October 2012 - 05:15 AM
Reason for edit:: Added code tags

New Topic/Question
Reply



MultiQuote





|