I'm sorry if this topic re-post.
I've problem showing menu with sub menu in website.
i want show sub menu when menu click.
like this one :
*home
*Tools
*about
*site map
when i click tools menu it's will be like this
*home
*tools
-pen
-pencil
-eraser
*about
*site map
what must i do?
thanks.
create Sub menu
Moderator: General Moderators
Re: create Sub menu
You would need to use JavaScript if you wish to make it more fluent, as PHP will cause the page to load. But if you want to do it with PHP, you could do something like this.
You should be able to figure that out.
The $links array seems obvious enough to modify.
Code: Select all
<?php
// This function will read in an array, if the keys are arrays they will be treated as categories, otherwise they will be treated as hyperlinks
function build_links_menu($links,$cat) {
$menu = '';
foreach($links as $key=>$value) {
if(is_array($links[$key])) {
$menu .= '* <a href="?cat='.urlencode($key).'">'.$key.'</a><br />'."\n";
if($key == $cat) {
foreach($links[$key] as $key2=>$value2)
$menu .= '- <a href="'.$value2.'">'.$key2.'</a><br />'."\n";
}
}
else
$menu .= ' <a href="'.$value.'">'.$key.'</a><br />'."\n";
}
return $menu;
}
$cat = (isset($_GET['cat']) && !empty($_GET['cat'])) ? urldecode($_GET['cat']) : null; // Fetch the category
// Map out the categories
$links = array(
'home' => array('example'=>'example.html','example2'=>'example2.html'),
'example3' => 'example3.html',
'tools' => array('pen'=>'example4.html','pencil'=>'example5.html','eraser'=>'eraser.html'),
'about' => array(),
'site map' => array(),
);
$links_menu = build_links_menu($links,$cat);
?>
<html>
<!-- You can place your HTML here -->
<body>
<?php echo $links_menu; ?>
</body>
</html>
Re: create Sub menu
thanks AlanG.
it's that code can read data from databases?
i want link read from database.
where i put query for read from databases?
it's that code can read data from databases?
i want link read from database.
where i put query for read from databases?
Re: create Sub menu
Yeah, you will need to modify the links array. What's the layout of your database table?
Re: create Sub menu
I'm new one.
what is the database layout?
if you mean database table and field,here they are;
database name "Project" with table "Cars" and field are: carCode,careName,carsType,detail,inputUser,inputtime
what is the database layout?
if you mean database table and field,here they are;
database name "Project" with table "Cars" and field are: carCode,careName,carsType,detail,inputUser,inputtime