function optimization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I developed a function that returns the section trace of a specific
section in a website. For example:

If section ABOUT US has the id_section = 18, then
get_seccion_trace(18) should return:

$arr[0] = 'About Us'
$arr[1] = 'Our Company'
$arr[2] = 'Start'

Then, i use something like this to make it legible for the final user:
$arr = array_reverse($hash);
//this prints Start > Our Company > About Us
echo implode(' » ',$arr);

Till know everything works fine. I was just wondering: Is there a any
way to optimize the function? I dont know if the -while loop- could
consume less resources with another recursive algorithm ... Here's the
code:

function get_seccion_trace($id) {
	global $cnn;
	$trace = array();
	$sql = 'SELECT * FROM section WHERE id_section='.q($id);
	$rs = &$cnn->Execute($sql);
	while(!$rs->EOF) {
		$trace[] = $rs->fields['title'];
		$sql = 'SELECT * FROM section WHERE
id_section='.$rs->fields['id_section_parent'];
		$rs = &$cnn->Execute($sql);
	}
	return $trace;
}


Thanks,
Andres S.
Gye, Ecuador


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Everything you need is one click away.  Make Yahoo! your home page now.
http://us.click.yahoo.com/AHchtC/4FxNAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux