Jump to content

Function not returning variable


Recommended Posts

Hey Guys,

I have no idea why this function is not returning the variable $new_cats, it's echoing correctly, but nothing is getting returned. Am I missing something??? Thanks!


Category Function:

function getCategories($cat_id, $level=0, $cats='') {  
	global $db;

	if($level == 0){
		$cats = array();

	$sql = "SELECT parentid, name FROM categories WHERE id = $cat_id";
	$result = $db->query($sql);
	list ($p, $n) = $db->fetchRow($result);

	$cats[] = $n;

	if ($p != '0') $this->getCategories($p, $level+1, $cats);

	if($p == '0'){
		$new_cats = '';
		foreach($cats as $cat){
			$new_cats .= "$cat » ";

		$new_cats = substr($new_cats, 0, -9);

		echo $new_cats;

		return $new_cats;


test page:

if($cats = $catalog->getCategories(62)){
	echo $cats;
	echo '<br /><br />No cats!';

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.