Below is the code that not returning anything but echoing values; it should return 'something' on false of if($return['status']=='Active')

function product($ids)
{
    $return = mysql_fetch_array(mysql_query("select * from tbl_product where id = $ids"));
    if($return['category_id'])
        $recursive_return = recursive($return['category_id']);  

    $recursive_return;  
}

function recursive($category_id)
{
    $return = mysql_fetch_array(mysql_query("select * from tbl_main_category where id = $category_id"));
    if($return['status']=='Active')
        recursive($return['parentId']);
    else
        $rr = 'something';

    return $rr; 
}

$return = product(1049);
echo $return;

Recommended Answers

All 2 Replies

before answering your question, what is your purpose for using the PHP recursive function or a function that calls itself?

Just give me one reason why.

In line 12; I am using a table with parentid within itself and status; that means I have unlimited category and subcategory; suppose if a category's status is inactive the it's all sub-category will be inactive. So, I want to check inactive status of its parent-category.

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.