Hi,
I have a recursive function that loads categories and sub-categories and displays them as a jQuery tree on my page.
The code takes a lot of time to run. What can I do to minimize the load time?
Function is below. Please help. Thanks
I have a recursive function that loads categories and sub-categories and displays them as a jQuery tree on my page.
The code takes a lot of time to run. What can I do to minimize the load time?
Function is below. Please help. Thanks
Code:
function catsTree($selected, $parent, $level){
$level = $level + 1;
require('config.php');
$sql = "SELECT name, id_cat, id_parent FROM cat where online = 1 and trash = 0 and id_parent = " . $parent . " order by name";
$result = mysql_query($sql) or die('error, query failed');
$num = mysql_num_rows($result);
$i=0;
if($num > 0){
if($level > 1){
echo '<ul>';
}
while ($i < $num){
echo '<li><span>';
echo mysql_result($result,$i,"name");
echo '</span>';
catsTree($selected, mysql_result($result,$i,"id_cat"), $level);
products(mysql_result($result,$i,"id_cat"));
echo '</li>';
$i++;
}
if($level > 1){
echo '</ul>';
}
}
}





