0

I have this function, but don't "return" any data;

function getCategoryParent($db,$id,$count = 12){
$parentID=0;
$inner = "";
for ($i=2; $i<=$count; $i++){
    $inner .=' INNER JOIN services_categories as x'.$i.' ON x'.$i.'.sc_id=x'.($i-1).'.sc_top_id ';
}
$sql='SELECT x'.$count.'.* FROM services_categories as x1 ' .$inner. ' WHERE x1.sc_id="'.$id.'" LIMIT 1';
$query=$db->query($sql,PDO::FETCH_ASSOC);
if($query->rowCount()){
    foreach ($query as $key) {
        $parentID=$key["sc_id"];
        return $parentID;

    }
}else{
    getCategoryParent($db,$id,$count-1);
} }

I want return sc_id or all query data. it's working with echo

0 Answers0