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?
1 Answer 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
user5147376user5147376
-
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?MarciSM– MarciSM07/23/2015 10:22:18Commented Jul 23, 2015 at 10:22
lang-php
function get_pathS($node, $manage = null)