[eluser]redraw[/eluser]
Dear all,
sorry for my bad english.
I want build a menu + submenu from database :
here my database :
Code:
/*
SQLyog Ultimate - MySQL GUI v8.2
MySQL - 5.1.33-community-log : Database - dbrsmp
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`dbrsmp` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `dbrsmp`;
/*Table structure for table `ms_akses` */
DROP TABLE IF EXISTS `ms_akses`;
CREATE TABLE `ms_akses` (
`akses_id` int(10) DEFAULT NULL,
`tgl_on` date DEFAULT NULL,
`tgl_off` date DEFAULT NULL,
`aktif` tinyint(4) DEFAULT NULL,
`program_id` int(10) DEFAULT NULL
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
/*Data for the table `ms_akses` */
insert into `ms_akses`(`akses_id`,`tgl_on`,`tgl_off`,`aktif`,`program_id`) values (1,'0000-00-00',NULL,NULL,1),(2,'0000-00-00',NULL,NULL,1),(1,'0000-00-00',NULL,NULL,3),(1,'0000-00-00',NULL,NULL,2);
/*Table structure for table `ms_program` */
DROP TABLE IF EXISTS `ms_program`;
CREATE TABLE `ms_program` (
`program_id` int(10) NOT NULL AUTO_INCREMENT,
`program` varchar(50) DEFAULT NULL,
`subprogram_id` int(10) DEFAULT NULL,
`link` varchar(100) DEFAULT NULL,
PRIMARY KEY (`program_id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
/*Data for the table `ms_program` */
insert into `ms_program`(`program_id`,`program`,`subprogram_id`,`link`) values (1,'AKUNTANSI',1,'1'),(2,'FARMASI',2,'2'),(3,'LABORATORIUM',NULL,'3'),(4,'RADIOLOGI',NULL,'4'),(5,'PENDAFTARAN POLI',NULL,'5'),(6,'PENDAFTARAN UGD',NULL,'6');
/*Table structure for table `ms_subprogram` */
DROP TABLE IF EXISTS `ms_subprogram`;
CREATE TABLE `ms_subprogram` (
`subprogram_id` int(10) DEFAULT NULL,
`subprogram` varchar(50) DEFAULT NULL
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*Data for the table `ms_subprogram` */
insert into `ms_subprogram`(`subprogram_id`,`subprogram`) values (1,'GL'),(2,'Obat'),(2,'Abit');
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
my model :
Code:
class Menumodel extends Model{
function Menumodel()
{
parent::Model();
}
function ambil_menu()
{
$this->db->select('*');
$this->db->from('ms_user');
$this->db->join('ms_akses', 'ms_user.akses_id = ms_akses.akses_id');
$this->db->join('ms_program', 'ms_akses.program_id = ms_program.program_id');
$this->db->join('ms_subprogram', 'ms_program.subprogram_id = ms_subprogram.subprogram_id');
$this->db->where('ms_user.user_id',from_session('user_id'));
$data = $this->db->get();
return $data;
$data = $this->db->get();
return $data;
}
}
my controller :
Code:
function index()
{
$data['detail'] = $this->menumodel->ambil_menu();
$this->load->view('haluser/index',$data);
}
my view :
Code:
<ul class="dropdown dropdown-horizontal">
<?php foreach ($detail->result() as $rows) : ?>
<li><?php echo anchor('home/'.$rows->program,$rows->program); ?>
<ul>
<li><?php echo anchor('home/'.$rows->subprogram,$rows->subprogram); ?></li>
</ul>
</li>
<?php endforeach; ?>
</ul>
The menu and sub menu can show up on the site, but it's goes wrong
user which have user_id = 'admin' it should have 3 menu
menu 1 with 1 sub menu (gl)
menu 2 with 2 sub menu (obat, abit)
menu 3 without sub menu
but in the view.php it's only show menu 1 and 2 which mean it's only show the menu that have submenu. the menu which dont have a submenu it's not show up.
not only that..
menu 2 is double show up on the view.php with each sub menu.. like this
menu 2 -> sub menu 1 (obat)
menu 2 -> sub menu 2 (abit)
not just like this :
menu 2 ->2 sub menu 1 (obat) and sub menu 2 (abit)
all i want is all menu show up somehow depending user access on database, not depending sub menu
please help me..
thank you