0
ID NAME PARENT_ID 
1 Sales 
2 Marketing 1
3 sales_optimiztaion.txt 2 
5 list.xls 6
6 General data 1

I have hierarchial table with data and function which counts how many files contains some specific folder and its subfolders. In this case folder Sales contains two files - list.xls an sales_optimiztaion.txt. Function:

<?
function get_pathS($node) { 
global $countSS;
$result = mysql_query('SELECT NAME, PARENT_ID FROM b_disk_object 
 WHERE ID="'.$node.'";'); 
$ro = mysql_fetch_array($result); 
 if ($ro['NAME']!='') { 
 $path=$ro['NAME'];
 if($path=='Sales'){
 $countSS++;
 $path=get_path($ro['PARENT_ID']);
 }
 $path=get_pathS($ro['PARENT_ID']);
}
 return $countSS;

} ?>

Function works fine, but I want to pass 'Sales' as an argument to the function like this:

<?
function get_pathS($node, $manage) { 
global $countSS;
$result = mysql_query('SELECT NAME, PARENT_ID FROM b_disk_object 
 WHERE ID="'.$node.'";'); 
$ro = mysql_fetch_array($result); 
 if ($ro['NAME']!='') { 
 $path=$ro['NAME'];
 if($path==$manage){
 $countSS++;
 $path=get_path($ro['PARENT_ID']);
 }
 $path=get_pathS($ro['PARENT_ID']);
}
 return $countSS;
} ?>

But after calling function like this:

while ($row = mysql_fetch_array($query)){
 $check='Sales';
 get_pathS($row['PARENT_ID'], $check);
 .......

It does not work. Whats the problem?

asked Jul 23, 2015 at 9:39
3
  • Does it work when you provide a default value for the second parameter? Like: function get_pathS($node, $manage = null) Commented Jul 23, 2015 at 9:44
  • It works, but returns incorrect count Commented Jul 23, 2015 at 9:50
  • I have declared $countSS as global variable, but what is alternative of this, because I have to call this function multiple times and each time it adds result to previous function call result? Commented Jul 23, 2015 at 10:30

1 Answer 1

1

when you call this (in function body)

$path=get_pathS($ro['PARENT_ID']);

you should pass here second argument too. like this

$path=get_pathS($ro['PARENT_ID'], $manage);
answered Jul 23, 2015 at 9:54
1
  • One more question... I have declared $countSS as global variable, but what is alternative of this, because I have to call this function multiple times and each time it adds result to previous function call result? Commented Jul 23, 2015 at 10:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.