10/10/2018, 10:51
[Help] Làm menu 2 cấp lên đa cấp Card 100k cho ai giúp đở
Hiện tại em có cái menu php chỉ được cấp 2 em muốn lên cấp 3 làm mãi không được ( buồn quá
demo menu cấp 2 hiện tại

Nhờ máy anh giúp em với
file product_category.php như sau
và SQL đây

cảm ơn các anh trước nhé
có gì liên hệ skykute.production@yahoo.com
demo menu cấp 2 hiện tại

Nhờ máy anh giúp em với
file product_category.php như sau
PHP Code:
<? $sql="select * from tbl_product_category where parent=2 order by sort";
$result=@mysql_query($sql,$conn);
$i=1;
while($row=mysql_fetch_assoc($result)){
?>
<tr>
<td class="stylemenu" onclick="showhide('s<?=$i?>')" style="cursor:pointer;"><a href="#1" class="link2"><?=$row***91;"name"***93;?></a></td>
</tr>
<tr>
<td id="s<?=$i?>" style="display:none"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<? $s="select * from tbl_product_category where parent='".$row***91;"id"***93;."' order by sort";
$kq=@mysql_query($s,$conn);
while($r=mysql_fetch_assoc($kq))
{
?>
<tr>
<td class="stylesubmenu"><a href="./?frame=product&cat=<?=$r***91;'id'***93;?>" class="link2"><?=$r***91;"name"***93;?></a></td>
</tr>
<? }?>
</table></td>
</tr>
<?
$i++;}
?>
PHP Code:
-- phpMyAdmin SQL Dump
-- version 2.11.7
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 29, 2010 at 11:41 PM
-- Server version: 5.0.51
-- PHP Version: 5.2.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `test`
--
-- --------------------------------------------------------
--
-- Table structure for table `tbl_product_category`
--
CREATE TABLE IF NOT EXISTS `tbl_product_category` (
`id` int(11) NOT NULL auto_increment,
`code` varchar(225) character set utf8 collate utf8_unicode_ci default NULL,
`name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL default ',
`parent` int(11) NOT NULL default '0',
`subject` text character set utf8 collate utf8_unicode_ci,
`detail_short` text character set utf8 collate utf8_unicode_ci,
`detail` longtext character set utf8 collate utf8_unicode_ci,
`image` varchar(255) character set utf8 collate utf8_unicode_ci default NULL,
`image_large` varchar(255) character set utf8 collate utf8_unicode_ci default NULL,
`sort` int(11) NOT NULL default '0',
`status` int(11) NOT NULL default '0',
`date_added` datetime NOT NULL default '0000-00-00 00:00:00',
`last_modified` datetime NOT NULL default '0000-00-00 00:00:00',
`lang` varchar(5) character set utf8 collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`),
KEY `code` (`code`),
FULLTEXT KEY `code_2` (`code`),
FULLTEXT KEY `code_3` (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=496 ;
--
-- Dumping data for table `tbl_product_category`
--

cảm ơn các anh trước nhé
có gì liên hệ skykute.production@yahoo.com
Bài liên quan
- while($r=mysql_fetch_assoc($kq)) -> lấy menu cấp 2
cần menu cấp bao nhiêu nữa thì cho thêm vòng lặp lấy dữ liệu thôi
{
if (@$children[$id] && $level <= $maxlevel)
{
$html .='<ul>';
foreach ($children[$id] as $v)
{
$id = $v['id'];
$html .='<li>';
$url = "#";
if(count( @$children[$id] ))
{
$html .= sprintf('<a href="%s"><span>%s</span></a>', $url , $v['name']);
}
else
{
$html .= sprintf('<a href="%s"><span>%s</span></a>', $url, $v['name']);
}
$html = mosTreeMenu( $id, 0 , $html, $children, $maxlevel, $level+1);
$html .='</li>';
}
$html .='</ul>';
}
return $html;
}
$sql="select * from tbl_product_category order by sort";
$result=@mysql_query($sql,$conn);
while($row=mysql_fetch_assoc($result))
{
$pt = $row['parent'];
$list = @$children[$pt] ? $children[$pt] : array();
array_push( $list, $row );
$children[$pt] = $list;
}
$levellimit = 5;
$html .= mosTreeMenu( 0, 1, $html, $children, max( 0, $levellimit-1 ));
echo $html;
function showSelectMenu($id,$insert_text=" –-"){
$db =&JFactory::getDBO();
$query = 'select * from #__product_category where parent_id= '.$id;
$db->setQuery($query);
$rows = $db->loadObjectList();
if ($db->getErrorNum()) {
echo $db->stderr();
return false;
}
$str = ''; //new
foreach($rows as $row){
$str.= '<option value="'.$row->id.'">'.$insert_text.$row->name.'</option>';
$this->showSelectMenu($row->id,$insert_text." –-");//old
$str .= $this->showSelectMenu($row->id,$insert_text." –-");//new
}
return $str;
}
[=========> Bổ sung bài viết <=========]
Google "menu da cap" ra cả đống.
Mình có 2 cách, tùy bạn chọn:
C1:
function multi_menu( $parent = 0, $prefix_symbol = ''){
$output = '<ul>';
$Q = mysql_query("SELECT * FROM menu_table WHERE parent = " . $parent);
while( $row = mysql_fetch_object($Q)){
$output .= '<li>'.$prefix_symbol . ' ' . $row->name.'</li>';
$output .= multi_menu($row->id, '------');
}
$output .= '</ul>';
return $output;
}
C2: query 1 lần, ra mảng rồi dựa vào mảng để duyệt đệ quy.
$Q = mysql_query("SELECT * FROM menu_table");
while($row = mysql_fetch_object($Q)){
$menus ***91;***93; = $row;
}
//menu table (id, name, parent)
//(1, 'menu 1', 0);
//(2, 'menu 2', 1)
/etc...
function multi_menu($menus, $parent = 0, $prefix_symbol = ''){
//menus = array();
$output = '<ul>';
foreach( $menus as $menu){
if($menu->parent = $parent){
$output .= '<li>'.$prefix_symbol . $menu->name . '</li>';
$output .= multi_menu($menus, $menu->id, '-------');
}
}
$output .= '</ul>';
return $output;
}
Có mã số thì mình up lên cho.
Anh em đói kém quá nhỉ :p, có 100k bao người làm , thậm chí free cũng tranh nhau lun (đùa thôi )