Hi,
Below I have a script and have altered it a little to serve my purposes. What id like to do is if my “nav_hide” field equals “hide” then it hides that row.
I have tried adding this “if($design_online_connection[‘nav_hide’] != “”) { } into my script but I can’t seem to get it to work at all. Can anyone advise on how to do this please as I’m pulling my hair out trying to do it 😮
Below is the menu code:
[CODE]class MenuBuilder
{
var $conn;
var $items = array();
var $html = array();
function MenuBuilder(&$db)
{
$this->conn = $db;
}
function fetch_assoc_all( $sql )
{
$result = mysql_query( $sql, $this->conn );
if ( !$result )
return false;
$assoc_all = array();
while( $fetch = mysql_fetch_assoc( $result ) )
$assoc_all[] = $fetch;
mysql_free_result( $result );
return $assoc_all;
}
function get_menu_items()
{
$sql = ‘SELECT id, parent_id, title, link, position, nav_hide FROM menu_item ORDER BY parent_id, position;’;
return $this->fetch_assoc_all( $sql );
}
function get_menu_html( $root_id = 0 )
{
$this->html = array();
$this->items = $this->get_menu_items();
foreach ( $this->items as $item )
$children[$item[‘parent_id’]][] = $item;
$loop = !empty( $children[$root_id] );
$parent = $root_id;
$parent_stack = array();
$this->html[] = ‘<ul>’;
while ( $loop && ( ( $option = each( $children[$parent] ) ) || ( $parent > $root_id ) ) )
{
if ( $option === false )
{
$parent = array_pop( $parent_stack );
$this->html[] = str_repeat( “t”, ( count( $parent_stack ) + 1 ) * 2 ) . ‘</ul>’;
$this->html[] = str_repeat( “t”, ( count( $parent_stack ) + 1 ) * 2 – 1 ) . ‘</li>’;
}
elseif ( !empty( $children[$option[‘value’][‘id’]] ) )
{
$tab = str_repeat( “t”, ( count( $parent_stack ) + 1 ) * 2 – 1 );
// HTML for menu item containing childrens (open)
$this->html[] = sprintf(
‘%1$s<li class=”has-sub” id=”%3$s”><a href=”/page.php?ID=%2$s”>%3$s</a>’,
$tab, // %1$s = tabulation
$option[‘value’][‘id’], // %2$s = link (URL)
$option[‘value’][‘title’], // %3$s = title
$option[‘value’][‘nav_hide’] // %4$s = nav hide
);
$this->html[] = $tab . “t” . ‘<ul class=”submenu”>’;
array_push( $parent_stack, $option[‘value’][‘parent_id’] );
$parent = $option[‘value’][‘id’];
}
else
// HTML for menu item with no children (aka “leaf”)
$this->html[] = sprintf(
‘%1$s<li id=”%3$s”><a href=”/page.php?ID=%2$s”>%3$s</a></li>’,
str_repeat( “t”, ( count( $parent_stack ) + 1 ) * 2 – 1 ), // %1$s = tabulation
$option[‘value’][‘id’], // %2$s = link (URL)
$option[‘value’][‘title’] , // %3$s = title
$option[‘value’][‘nav_hide’] // %4$s = nav hide
);
}
// HTML wrapper for the menu (close)
$this->html[] = ‘</ul>’;
return implode( “rn”, $this->html );
}
}
Kind Regards
Joe