I am having a problem with making the links in my bar work properly the database is setup like so my db http://bloodkittens.com/resources/upload/db.png
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
mysql_connect("localhost", "dbuser", "******");
mysql_select_db("guild");
// prepare special array with parent-child relations
$menuData = array(
'items' => array(),
'parents' => array()
);
$result = mysql_query("SELECT id_menu id, parentID_menu parentId, label_menu name FROM main_menu` ORDER BY parentID_menu");
while ($menuItem = mysql_fetch_assoc($result))
{
$menuData['items'][$menuItem['id']] = $menuItem;
$menuData['parents'][$menuItem['parentId']][] = $menuItem['id'];
}
// menu builder function, parentId 0 is the root
function buildMenu($parentId, $menuData)
{
$html = '';
$parent='';
if (isset($menuData['parents'][$parentId]))
{
$menuClass= ($parentId==0) ? ' class="navbar" id="navbar"' : '';
$parent= ($parentId==0) ? 0 : 1;
$html = "<ul{$menuClass}>\n";
foreach ($menuData['parents'][$parentId] as $itemId)
{
//subment
$result=mysql_query("select * from main_menu where parentID_menu='$itemId'");
if (mysql_num_rows($result)>(int)0 && $parentId!=0) {
$subm =' class="navbar"';
}else{
$subm ='';
}
//end
$menu = $parentId == 0 ? ' class="menulink"' : ''; //class of main menu
$html .= '<li>' . "<a{$subm}{$menu} href=\"#\" >{$menuData['items'][$itemId]['name']}</a>";
// find childitems recursively
$html .= buildMenu($itemId, $menuData);
$html .= '</li>';
}
$html .= '</ul>';
}
return $html;
}
// output the menu
echo buildMenu(0, $menuData);
?>
How would i make it so that the value link_menu would be the href in the code for each separate entry in the db? rather then \'#\' because the code works completely and i'm very happy how it looks after i apply my css to it but the links aren't working
For work the menu sorting
must be add a new field in the table,
and change this query from
$result = mysql_query("SELECT id_menu id, parentID_menu parentId, label_menu name, link_menu link FROM main_menu ORDER BY parentID_menu");
to :
$result = mysql_query("SELECT id_menu id, parentID_menu parentId, label_menu name, link_menu link FROM main_menu ORDER BY menu_sort");
you never seem to select it
$result = mysql_query("SELECT id_menu id, parentID_menu parentId, label_menu, link_menu, name FROM main_menu ORDER BY parentID_menu");
and then..
$html .= '<li>' . "<a{$subm}{$menu} href=\"{$menuData['items'][$itemId]['link_menu']}\" >{$menuData['items'][$itemId]['name']}</a>";
Instead of href=\"#\" >, use this:
href=\"{$menuData['items'][$itemId]['link_menu']}\" >
the code that i used was in the end like this i think i got it to work by pure luck but regardless i win : )
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
mysql_connect("localhost", "BloodKittens", "Zangoshi1");
mysql_select_db("bloodkittens");
// prepare special array with parent-child relations
$menuData = array(
'items' => array(),
'parents' => array(),
'links' => array()
);
$result = mysql_query("SELECT id_menu id, parentID_menu parentId, label_menu name, link_menu link FROM main_menu ORDER BY parentID_menu");
while ($menuItem = mysql_fetch_assoc($result))
{
$menuData['items'][$menuItem['id']] = $menuItem;
$menuData['parents'][$menuItem['parentId']][] = $menuItem['id'];
$menuData['links'] = $menuItem['link'];
}
// menu builder function, parentId 0 is the root
function buildMenu($parentId, $menuData)
{
$html = '';
$parent='';
if (isset($menuData['parents'][$parentId]))
{
$menuClass= ($parentId==0) ? ' class="navbar" id="navbar"' : '';
$parent= ($parentId==0) ? 0 : 1;
$html = "<ul{$menuClass}>\n";
foreach ($menuData['parents'][$parentId] as $itemId)
{
//subment
$result=mysql_query("select * from main_menu where parentID_menu='$itemId'");
if (mysql_num_rows($result)>(int)0 && $parentId!=0) {
$subm =' class="navbar"';
}else{
$subm ='';
}
//end
$menu = $parentId == 0 ? ' class="menulink"' : ''; //class of main menu
$html .= '<li>' . "<a{$subm}{$menu} href=\"{$menuData['items'][$itemId]['link']}\" >{$menuData['items'][$itemId]['name']}</a>";
// find childitems recursively
$html .= buildMenu($itemId, $menuData);
$html .= '</li>';
}
$html .= '</ul>';
}
return $html;
}
// output the menu
echo buildMenu(0, $menuData);
?>
Related
With PHP, I need to create a three-level-deep navbar. I have data like this:
And I need it to be organized like so:
Napkins
--Colored Napkins
----American Tradition
--White Beverage Napkins
----American Digital
----American Tradition
----American Hi-Speed
--White Luncheon Napkins
----American Digital
----American Tradition
----American Hi-Speed
--White Dinner Napkins
...(etc)...
Plates
--Eco-Plates
----American Tradition
--Plastic Trays
...(etc)...
Just using a relatively simple <ul> structure with <li> and <a>. Clearly a loop is needed to go through the rows of data. And I know that I'd need to do lots of "testing" to see if the "current" category/subcategory/method matches the one from the previous iteration of the loop.
But I'm having trouble getting the <ul> and <li> tags to close at the correct locations and to not show the print method tier when there is only one print method for a given category/subcategory. Or when there is no print method (sometimes it can be null, such as for plastic utensils). How can I set this up?
Edit
The code I have so far, which almost works, but is very clunky ($items is the data from the database):
function addMethodMenuItem($result, $short_cat_name, $short_subcat_name, $short_method_name, $this_method_name)
{
$result .= "<li>";
$result .= "<a";
$result .= " href=\"product.php?category={$short_cat_name}&subcategory={$short_subcat_name}&printMethod={$short_method_name}\"";
$result .= " target=\"_self\"";
$result .= " title=\"{$this_method_name}\">";
$result .= $this_method_name;
$result .= "</a>";
$result .= "</li>";
return $result;
}
function addSubMenuItem($item, $previous_cat_name, $previous_subcat_name, $result, $newCat)
{
$this_cat_name = $item["category_name"];
$this_subcat_name = $item["subcategory_name"];
$this_method_name = $item["method_name"];
$short_cat_name = $item["category_short"];
$short_subcat_name = $item["subcategory_short"];
$short_method_name = $item["method_short"];
if ($this_subcat_name != $previous_subcat_name || $this_cat_name != $previous_cat_name) { // We have to create a new "subcategory" menu item
if ($previous_subcat_name != null && !$newCat) { // if this isn't the first subcategory menu item of the category.
$result .= "</ul></li>";
}
$result .= "<li>";
$result .= "<a class=\"ajxsub\"";
$result .= " href=\"#\">";
$result .= $this_subcat_name;
$result .= "</a>";
$result .= "<ul>";
}
$result = addMethodMenuItem($result, $short_cat_name, $short_subcat_name, $short_method_name, $this_method_name);
return $result;
}
function printMenu(array $items, $previous_cat_name, $result)
{
// $result .= "<ul>";
$previous_subcat_name = null;
foreach ($items as $item) {
$newCat = false;
$this_cat_name = $item["category_name"];
$this_subcat_name = $item["subcategory_name"];
if ($this_cat_name != $previous_cat_name) {
if ($previous_cat_name != null) { // if this isn't the very first top-level menu item.
$result .= "</ul></li>";
$result .= "</ul></li>";
$newCat = true;
}
$result .= "<li>";
$result .= "<a class=\"ajxsub\"";
$result .= " href=\"#\">";
$result .= $this_cat_name;
$result .= "</a>";
$result .= "<ul>";
}
$result = addSubMenuItem($item, $previous_cat_name, $previous_subcat_name, $result, $newCat);
$previous_subcat_name = $this_subcat_name;
$previous_cat_name = $this_cat_name;
}
$result .= "</ul></li>";
// $result .= "</ul>";
return $result;
}
Give this a whirl - assumes you have the data already sorted (else sort it first):
$flds = ['category_name', 'subcategory_name', 'method_name'];
$lval = ['it will never be this'];
$result = "";
$start = true;
foreach ($items as $item) {
if ($start) {
$result .= "<ul>";
$first = $start = false;
} else $first = true;
foreach ($flds as $k=>$val) {
if ($item[$val] != $lval[$k]) {
$result .= genhtml($k, $item[$val], $first);
$first = false;
$lval[$k] = $item[$val];
$lval[$k+1] = ''; // Don't care if this goes over the max
}
}
}
if (!$start) $result .= "</ul></li></ul></li></ul>\n";
echo $result;
function genhtml($level, $value, $first) {
switch ($level) {
case 0:
$close = $first ? "</ul></li></ul></li>" : "";
return "{$close}<li>{$value}<ul>\n";
case 1:
$close = $first ? "</ul></li>" : "";
return " {$close}<li>{$value}<ul>\n";
case 2:
return " <li>{$value}</li>\n";
default:
throw new Exception("I don't know how to do '{$level}'");
}
}
The code above (with some of your data) produces:
<ul><li>Napkins<ul>
<li>Colored Napkins<ul>
<li>American Tradition</li>
</ul></li><li>White Beverage Napkins<ul>
<li>American Digital</li>
<li>American Tradition</li>
<li>American Hi Speed</li>
</ul></li><li>White Luncheon Napkins<ul>
<li>American Digital</li>
<li>American Tradition</li>
<li>American Hi Speed</li>
</ul></li><li>White Dinner Napkins<ul>
<li>American Digital</li>
<li>American Tradition</li>
<li>American Hi Speed</li>
</ul></li></ul></li><li>Plates<ul>
<li>Eco Plates<ul>
<li>American Tradition</li>
</ul></li></ul></li></ul>
(Not pretty, but I think its right).
Also will ignore duplicate records (maybe not what you want?). If you need other data from your record to produce the html, pass $item to genhtml as well.
i am trying to build a recursive tree but child function is not returning any value. i don't know how to return value in PHP code. is there i am doing any mistake. please help
$sql="select * from MenuMaster order by MenuId";
$result= ExecuteQuery($sql);
function BuildMenu($result){
$output ='';
$output .= '<Ul>';
while ($row = mysqli_fetch_array ($result)){
if($row['ParentId']== null || $row['ParentId'] ==0){
$output .= '<li>'.$row['MenuText'].'</li>';
}
$output .= FindChild($output , $row['MenuId']);
}
$output.= '</Ul>';
return $output;
}
$finaloutput.= BuildMenu($result);
echo $finaloutput;
function FindChild($childOutput, $Menuid){
$sqlChild="select * from MenuMaster where ParentId = $Menuid ";
$resultChild= ExecuteQuery($sqlChild);
$Rowcont =mysqli_num_rows($resultChild);
if($Rowcont > 0){
$childOutput.='<Ul>';
while ($row1 = mysqli_fetch_array ($resultChild)){
$childOutput.= '<li>'.$row1['MenuText'].'</li>';
FindChild($childOutput,$row1['MenuId']);
}
$childOutput.='</Ul>';
}
return $childOutput;
}
Problem:
I am trying to delete all sublevels of a category by using a class. Currently I can only make it delete two sublevels, not three.
The database table:
CREATE TABLE betyg_category (
CID int(11) NOT NULL AUTO_INCREMENT,
Item varchar(100) NOT NULL,
Parent int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (CID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The PHP class:
<?php
class ItemTree
{
var $itemlist = array();
function ItemTree($query)
{
$result = mysql_query($query) or die ('Database Error (' . mysql_errno() . ') ' . mysql_error());
while ($row = mysql_fetch_assoc($result))
{
$this->itemlist[$row['CID']] = array(
'name' => $row['Name'],
'parent' => $row['Parent']
);
}
}
function get_tree($parent, $with_parent=0)
{
$item_tree = array();
if ($with_parent == 1 && $parent != 0)
{
$item_tree[$parent]['name'] = $this->itemlist[$parent]['name'];
$item_tree[$parent]['parent'] = $this->itemlist[$parent]['parent'];
$item_tree[$parent]['child'] = $this->get_tree($parent);
return $item_tree;
}
foreach ($this->itemlist as $key => $val)
{
if ($val['parent'] == $parent)
{
$item_tree[$key]['name'] = $val['name'];
$item_tree[$key]['parent'] = $val['parent'];
$item_tree[$key]['child'] = $this->get_tree($key);
}
}
return $item_tree;
}
function make_optionlist ($id, $class='', $delimiter='/')
{
$option_list = '';
$item_tree = $this->get_tree(0);
$options = $this->make_options($item_tree, '', $delimiter);
if (!is_array($id))
{
$id = array($id);
}
foreach($options as $row)
{
list($index, $text) = $row;
$selected = in_array($index, $id) ? ' selected="selected"' : '';
$option_list .= "<option value=\"$index\" class=\"$class\"$selected>$text</option>\n";
}
return $option_list;
}
function make_options ($item_tree, $before, $delimiter='/')
{
$before .= empty($before) ? '' : $delimiter;
$options = array();
foreach ($item_tree as $key => $val)
{
$options[] = array($key, '- '.$before.$val['name']);
if (!empty($val['child'])) {
$options = array_merge($options, $this->make_options($val['child'], $before.$val['name'], $delimiter));
}
}
return $options;
}
function get_navlinks ($navid, $tpl, $startlink='', $delimiter=' ยป ')
{
// $tpl typ: {name}
$search = array('{id}', '{name}');
$navlink = array();
while (isset($this->itemlist[$navid]))
{
$replace = array($navid, $this->itemlist[$navid]['name']);
$navlink[] = str_replace($search, $replace, $tpl);
$navid = $this->itemlist[$navid]['parent'];
}
if (!empty($startlink))
{
$navlink[] = str_replace($search, array(0, $startlink), $tpl);
}
$navlink = array_reverse($navlink);
return implode($delimiter, $navlink);
}
function show_tree ($parent=0, $tpl='%s', $ul_class='', $li_class='')
{
$item_tree = $this->get_tree($parent);
return $this->get_node($item_tree, $parent, $tpl, $ul_class, $li_class);
}
function get_node ($item_tree, $parent, $tpl, $ul_class, $li_class)
{
// $tpl typ: {name}
$search = array('{id}', '{name}');
$output = "\n<ul class=\"$ul_class\">\n";
foreach ($item_tree as $id => $item)
{
$replace = array($id, $item['name']);
$output .= "<li class=\"$li_class\">".str_replace($search, $replace, $tpl);
$output .= !empty($item['child']) ? "<br />".$this->get_node ($item['child'], $id, $tpl, $ul_class, $li_class) : '';
$output .= "</li>\n";
}
return $output . "</ul>\n";
}
function get_id_in_node ($id)
{
$id_list = array($id);
if (isset($this->itemlist[$id]))
{
foreach ($this->itemlist as $key => $row)
{
if ($row['parent'] == $id)
{
if (!empty($row['child']))
{
$id_list = array_merge($id_list, get_id_in_node($key));
} else
{
$id_list[] = $key;
}
}
}
}
return $id_list;
}
function get_parent ($id)
{
return isset($this->itemlist[$id]) ? $this->itemlist[$id]['parent'] : false;
}
function get_item_name ($id)
{
return isset($this->itemlist[$id]) ? $this->itemlist[$id]['name'] : false;
}
}
?>
Scenario:
Say you have the following structure in a :
Literature
-- Integration of sources
---- Test 1
It will result in the following in the database table:
When I try to delete this sublevel, it will leave the last sublevel in the database while it should delete it. The result will be:
The PHP code:
//Check if delete button is set
if (isset($_POST['submit-deletecategory']))
{
//Get $_POST variables for category id
$CategoryParent = intval($_POST['CategoryList']);
//Check if category is selected
if ($CategoryParent != "#")
{
//Get parent category and subsequent child categories
$query = "SELECT CID, Item AS Name, Parent FROM " . TB_CATEGORY . " ORDER BY Name";
$items = new ItemTree($query);
if ($items->get_item_name($_POST['CategoryList']) !== false)
{
//Build up erase list
$CategoryErase = $items->get_id_in_node($CategoryParent);
$CategoryEraseList = implode(", ", $CategoryErase);
}
else
{
$CategoryEraseList = 0;
}
//Remove categories from database
$query = "DELETE FROM " . TB_CATEGORY . " WHERE CID IN ($CategoryEraseList)";
$result = mysql_query($query) or die ('Database Error (' . mysql_errno() . ') ' . mysql_error());
//Return a confirmation notice
header("Location: settings.php");
exit;
}
}
Thank you in advance for any guidance I can get to solve the issue.
Here is a way to do it : use a recursive function, which will first look for the leaf item (the deepest in your tree). You remove children first, then the parent. And for each child, you remove child's children first, etc...
deleteSub(1);
function deleteSub($cat_id) {
$request = "SELECT * FROM ". TB_CATEGORY ." WHERE Parent = ".$cat_id;
$results = mysql_query($request);
while($child = mysql_fetch_array($results))
{
deleteSub($child["CID"]);
}
$request = "DELETE FROM ". TB_CATEGORY ." WHERE CID = ".$cat_id;
return mysql_query($request);
}
A better way could be use this kind of recursive function to store CIDs in an array, then make a single DELETE request, but I think you'll be able to adapt this code.
I'm not going to read or try to understand the entire code, but it seems to me you need some sort of recursion function. What I basicly would do is create a function that goes up in the hierachy and one that goes down.
Note: It has been a while since i've written anything in procedural mysql, so please check if the mysql_num_rows(),mysql_fetch_array and so on is written in the correct manner
EDIT: I've just noticed you only wanted a downwards deletion and therefore zessx's answer is more valid
<?php
function recursiveParent($id) {
$sql = 'SELECT parent FROM betyg_category WHERE CID=' . $id;
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0) {
while($r = mysql_fetch_array($result,MYSQLI_ASSOC)) {
recursiveParent($r['parent']);
}
}
$sql = 'DELETE FROM betyg_category WHERE CID=' . $id;
mysql_query($sql);
}
function recursiveChild($parent) {
$sql = 'SELECT CID FROM betyg_category WHERE parent=' . $parent;
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0) {
while($r = mysql_fetch_array($result,MYSQLI_ASSOC)) {
recursiveChild($r['CID']);
}
}
$sql = 'DELETE FROM betyg_category WHERE parent=' . $parent;
mysql_query($sql);
}
function delete($id) {
recursiveParent($id);
recursiveChild($id);
}
?>
This is my way to do. instead of recursive the query to run, i get all the child's id first then only run query. here the code refer:-
First, defined a variable called $delete_node_list as array. (to store all node id that need to be delete)
function delete_child_nodes($node_id)
{
$childs_node = $this->edirectory_model->get_child_nodes($node_id);
if(!empty($childs_node))
{
foreach($childs_node as $node)
{
$this->delete_child_nodes($node['id']);
}
}
$this->delete_node_list[] = $node_id;
}
in mysql..
$sql = 'DELETE FROM betyg_category WHERE CID IN '.$this->delete_node_list;
mysql_query($sql);
I want to create a simple menu function which can call it example get_menu()
Here is my current code.
<?php
$select = 'SELECT * FROM pages';
$query = $db->rq($select);
while ($page = $db->fetch($query)) {
$id = $page['id'];
$title = $page['title'];
?>
<?php echo $title; ?>
<?php } ?>
How to do that in?
function get_menu() {
}
Let me know.
Here is the function for that:
function get_menu(&$db)
{
$select = 'SELECT * FROM pages';
$query = $db->rq($select);
$menu = '';
while ($page = $db->fetch($query)) {
$id = $page['id'];
$title = $page['title'];
$menu .= '<a href="page.php?id=' . $id . '" &title="' . $title .'></a>'
}
return $menu;
}
.
Some Quick Corrections In Your Script:
You were missing = after id
You were missing & after title
Suggestion:
You can give your menu links a class and style as per your menu needs :)
get_menu() has to get reference to $db somehow. Probably the best and easiest way is to pass that reference as parameter:
function get_menu(MyDatabaseHandler $db) {
// code proposed by Sarfraz here
}
now here you already have a mistake:
<?php echo $title; ?>
notice the = after id
you can't be too careful
First, separate the part where you're doing something, and the one used to display things.
Second, the alternative syntax looks better for the display part.
<?php
function get_menu(){
$items = array();
$select = 'SELECT * FROM pages';
$query = $db->rq($select);
while ($page = $db->fetch($query)) {
$items[] = $page['id'];
}
return $items;
}
$menuItems = get_menu();
?>
<ul>
<?php foreach($menuItems as $item): ?>
<li><?php echo $item['title']; ?></li>
<?php endforeach;?>
</ul>
The code Sarfraz posted is going to create invalid anchor tags (i.e. links). They'll also be missing names. Here is the shorter/faster version:
function get_menu($db)
{
$result = $db->rq('SELECT id,title FROM pages');
$menu = '';
while ($page = $db->fetch($result))
{
$id = $page['id'];
$title = $page['title'];
$menu .= "<a href='page.php?id={$id}&title={$title}'>{$title}</a>\n";
}
return $menu;
}
To use that do this:
echo get_menu($db);
The error you were getting was probably resulting from not passing the database connection to the function.
NOTE: It's generally not a good idea to show database ID numbers to the user in the interest of security; slugs are much better for identifying pages and are SEO friendly. Also, there shouldn't be any need to pass the page title to page.php because if you've got the ID you can get that when you need it from the database. Here's the code with this in mind:
function get_menu($db)
{
$result = $db->rq('SELECT id,title FROM pages');
$menu = '';
while ($page = $db->fetch($result))
{
$menu .= "<a href='page.php?id={$page['id']}'>{$page['title']}</a>\n";
}
return $menu;
}
just put function get_menu() { above your code and } below
or like this??
function get_menu( $title, $id ) {
$menu = '';
$menu .= '<a href="page.php?id' . $id . '" title="' . $title .'></a>'
echo $menu;
}
------------------------
$select = 'SELECT * FROM pages';
$query = $db->rq($select);
while ($page = $db->fetch($query)) {
$id = $page['id'];
$title = $page['title'];
get_menu($title, $id );
}
function getMenu()
{
$select = 'SELECT FROM pages';
$query = $db->rq($select);
$menu = new Array;
while ($page = $db->fetch($query)) {
$menu[] = '';
}
return $menu;
}
How would I create a nested list, I currently have this
public function getNav($cat,$subcat){
//gets all sub categories for a specific category
if(!$this->checkValue($cat)) return false; //checks data
$query = false;
if($cat=='NULL'){
$sql = "SELECT itemID, title, parent, url, description, image
FROM p_cat
WHERE deleted = 0
AND parent is NULL
ORDER BY position;";
$query = $this->db->query($sql) or die($this->db->error);
}else{
//die($cat);
$sql = "SET #parent = (SELECT c.itemID FROM p_cat c WHERE url = '".$this->sql($cat)."' AND deleted = 0);
SELECT c1.itemID, c1.title, c1.parent, c1.url, c1.description, c1.image, (SELECT c2.url FROM p_cat c2 WHERE c2.itemID = c1.parent LIMIT 1) as parentUrl
FROM p_cat c1
WHERE c1.deleted = 0
AND c1.parent = #parent
ORDER BY c1.position;";
$query = $this->db->multi_query($sql) or die($this->db->error);
$this->db->store_result(); $this->db->next_result();
$query = $this->db->store_result();
}
return $query;
}
public function getNav($cat=false, $subcat=false){
//gets a list of all categories form this level, if $cat is false it returns top level nav
if($cat==false || strtolower($cat)=='all-products') $cat='NULL';
$ds = $this->data->getNav($cat, $subcat);
$nav = $ds ? $ds : false;
$html = '';
//create html
if($nav){
$html = '<ul>';
//var_dump($nav->fetch_assoc());
while($row = $nav->fetch_assoc()){
$url = isset($row['parentUrl']) ? $row['parentUrl'].'/'.$row['url'] : $row['url'];
$current = $subcat==$row['url'] ? ' class="current"' : '';
$html .= '<li'.$current.'>'.$row['title'].'</li>';
}
$html .='</ul>';
}
return $html;
}
The sql returns parents and children, for each parent I need the child to nest in a list.
It's been a while since I've done any PHP but wondering if this will work. Inside your while loop, could you just recurse and add the output of getNav($cat = $row['url']) again in a new <li>, kind of like:
while($row = $nav->fetch_assoc()){
$url = isset($row['parentUrl']) ? $row['parentUrl'].'/'.$row['url'] : $row['url'];
$current = $subcat==$row['url'] ? ' class="current"' : '';
$html .= '<li'.$current.'>'.$row['title'].'';
/* Add subNav HTML */
$html .= $this->getNav($row['url']);
$html .= '</li>';
}
It seems that "getNav" refers to both the function to get the SQL as well as the function that renders the nav HTML - maybe change the HTML getNav function name to getNavHtml just for clarity.
Also seems like the $subcat argument may be able to be removed from the SQL getNav function since it is never used.