$template_file, "debug" => $debug, "global_vars" => 1, "loop_context_vars" => 1); $db = new MyDb; # create new MyDb class $body =& new Template($body_options); # create new Template class for body $db->db_connect($host, $user, $password); # connect to database $db->db_select($database); # select database $category = @$_REQUEST['category']; # obtain category $array = array(); $category_links = ""; $index_link = ""; if($category) { $sql = "select page_id, LinkCategoryID from paging where pagename = \"$category\" limit 1"; $db->db_query($sql); $page_id = $db->db_assocset(); $sql = "select URL, Title, Description from Links where page_id = " . $page_id[0]['page_id']; $db->db_query($sql); $link_info = $db->db_assocset(); for($i = 0; $i < count($link_info); $i++) { $array[$i]['content'] = "" . $link_info[$i]['Title'] . "
\n" . $link_info[$i]['Description'] . "

"; } $sql = "select pagename from paging where LinkCategoryID = " . $page_id[0]['LinkCategoryID']; $db->db_query($sql); $cat_links = $db->db_assocset(); if($cat_links) { for($i = 0; $i < count($cat_links); $i++) { $category_links = $category_links . "[ " . ($i+1) . " ]  \n"; } } $index_link = 'Back to directory index'; } else { ############################################################ # select categories ############################################################ $sql = "select * from LinkCategories order by LinkCategoryName"; # select all the categories $db->db_query($sql); $categories = $db->db_assocset(); $num_cats = count($categories); # count number of categories $div_num = ceil($num_cats / $cols); # obtain number of rows to place per column in directory index ############################################################ # build array here ############################################################ for($i = 0, $j = 0, $k = 0; $i < $num_cats; $i++) { $array[$i]['content'] = "" . " " . trim($categories[$j]['LinkCategoryName']) . "
" ; if($k == $div_num-1 && ($num_cats - $j) > 0) { $i++; $num_cats++; $k = -1; $array[$i]['content'] = ""; } $j++; $k++; } } $body->AddParam('category_loop', $array); $body->AddParam('category_links', $category_links); $body->AddParam('index_link', $index_link); $body->EchoOutput(); ?>