Просмотр поста

.
Koenig
(\/)____o_O____(\/)

Screamer, мой вариант
если я правильно понял

<?php
//   test access

$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_name = 'qwerty';
$db_charset = 'utf-8';

$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name); 
if ($mysqli->connect_errno) { 
die('Connect Error: ' . $mysqli->connect_errno); 
} else { 
$mysqli->set_charset('utf8'); 
}

/*
-- phpMyAdmin SQL Dump
-- version 3.2.3
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 17, 2012 at 05:36 PM
-- Server version: 5.1.40
-- PHP Version: 5.3.3

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `qwerty`
--

-- --------------------------------------------------------

--
-- Table structure for table `cms_access_list`
--

CREATE TABLE IF NOT EXISTS `cms_access_list` (
  `gid` int(11) unsigned NOT NULL,
  `mid` int(11) unsigned NOT NULL,
  PRIMARY KEY (`gid`,`mid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `cms_access_list`
--

INSERT INTO `cms_access_list` (`gid`, `mid`) VALUES
(4, 4),
(4, 5),
(5, 1),
(5, 2),
(5, 3);

-- --------------------------------------------------------

--
-- Table structure for table `cms_modules`
--

CREATE TABLE IF NOT EXISTS `cms_modules` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `module` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `cms_modules`
--

INSERT INTO `cms_modules` (`id`, `module`) VALUES
(1, 'test1'),
(2, 'test2'),
(3, 'test3'),
(4, 'test4'),
(5, 'test5');

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `group` int(11) unsigned NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `group`) VALUES
(1, 5),
(2, 4);

-- --------------------------------------------------------

--
-- Table structure for table `users_groups`
--

CREATE TABLE IF NOT EXISTS `users_groups` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `users_groups`
--

INSERT INTO `users_groups` (`id`, `name`) VALUES
(1, 'test1'),
(2, 'test2'),
(3, 'test3'),
(4, 'test4'),
(5, 'test5');

*/


$sql = "SELECT * FROM `users` JOIN `users_groups` JOIN `cms_access_list` JOIN `cms_modules` ON users.id =1 AND users.group = users_groups.id AND users_groups.id = cms_access_list.gid AND cms_access_list.mid = cms_modules.id";

$res = $mysqli->query($sql);
while($row = $res->fetch_assoc()) {
print_r($row);
echo '<hr/>';
}
?>