Please tell me why it gives me always zero value?

<?php
$total =0;

		$memid = $_POST['username'];
		$leg = $_POST['leg'];

mysql_connect ("host", "usr", "paswd") or die ('Error: ' .mysql_error());
mysql_select_db ("dbname");
function getTotalLeg($memid,$leg){	
$sql="select $leg from `users` where `username`='$memid' ";

$res=mysql_query($sql);
$row=mysql_fetch_array($res);

global $total;

$total = $total+mysql_num_rows($res);
            if($row['$leg']!=''){
                getTotalLeg ($row['$leg'],'lname');
                getTotalLeg ($row['$lrg'],'rname');
            }         
return $total;
}
echo $total;
?>

Please, solve it. I want to count how much i have in my left or right, sum of total in binary tree.

Member Avatar for diafol

That looks like a very convoluted piece of code. I'm sure there's an easier way of doing what you want. Could you please write out in steps (1. ... 2. ... etc), what you're trying to achieve.

I got the problem, i didn't call the function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.