0

Hi,
i developing web application in core php.
we have five panels superadmin, admin, medical, staff, customer.
all records should be display superadmin and created by users.
please help me to write a mysql query

below my basic query.

$user = $DB->prepare("SELECT `u_userid`, `u_username`, `u_password`, `u_rolecode`, `firstname`, `lastname`, `sex`, `age`, `email`, `telephone`, `mobile`, `company`, `location`, `address1`, `address2`, `country`, `profile`, `status` FROM `np_system_users`  ORDER BY u_userid LIMIT $start_from, 25");

table name: np_system_users

CREATE TABLE IF NOT EXISTS `np_system_users` (
  `u_userid` int(11) NOT NULL AUTO_INCREMENT,
  `u_username` varchar(100) NOT NULL,
  `u_password` varchar(255) NOT NULL,
  `u_rolecode` varchar(50) NOT NULL,
  `firstname` varchar(20) NOT NULL,
  `lastname` varchar(20) NOT NULL,
  `sex` varchar(10) NOT NULL,
  `age` varchar(10) NOT NULL,
  `email` varchar(50) NOT NULL,
  `telephone` varchar(20) NOT NULL,
  `mobile` varchar(20) NOT NULL,
  `company` varchar(50) NOT NULL,
  `location` varchar(100) NOT NULL,
  `address1` text NOT NULL,
  `address2` text NOT NULL,
  `country` varchar(10) NOT NULL,
  `profile` varchar(100) NOT NULL,
  `status` varchar(100) NOT NULL DEFAULT '0',
  `createdby` varchar(100) NOT NULL,
  `headofdomain` varchar(100) NOT NULL,
  `visible1` varchar(100) NOT NULL,
  `visible2` varchar(100) NOT NULL,
  `visible3` varchar(100) NOT NULL,
  PRIMARY KEY (`u_userid`),
  KEY `u_rolecode` (`u_rolecode`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Insert code

INSERT INTO `np_system_users` (`u_userid`, `u_username`, `u_password`, `u_rolecode`, `firstname`, `lastname`, `sex`, `age`, `email`, `telephone`, `mobile`, `company`, `location`, `address1`, `address2`, `country`, `profile`, `status`, `createdby`, `headofdomain`, `visible1`, `visible2`, `visible3`) VALUES
(33, 'Torsignia', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'SUPERADMIN', 'prabaweb', 'P', 'Male', '23', 'superadmin@prabaweb.com', '5476544767432', '86876767438', 'prabaweb', 'Koramangala 4 Block, Koramangala, Bengaluru, Karnataka, India', 'Koramangala 4 Block, Koramangala, Bengaluru, Karnataka, India', 'Koramangala 4 Block, Koramangala, Bengaluru, Karnataka, India', 'India', 'uploads/Screen Shot 2015-01-28 at 15.38.08.png', '1', 'superadmin@prabaweb.com', '', '', 'SUPERADMIN', ''),
(34, 'prabakaran', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'ADMIN', 'prabakaran', 'P', 'Male', '23', 'prabakaranp@hotmail.com', '89686567686', '867687686878', 'prabaweb', 'The Koramangala Club, Bengaluru, Karnataka, India', 'Koramangala, Bengaluru, Karnataka, India', 'Koramangala, Bengaluru, Karnataka, India', 'India', 'uploads/Penguins.jpg', '1', 'superadmin@prabaweb.com', '', '', 'SUPERADMIN', ''),
(36, 'staff', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'STAFF', 'staff', 's', 'Male', '23', 'staff@prabaweb.com', '56554764655', '646545656', 'prabaweb', 'Koramangala 4 Block, Koramangala, Bengaluru, Karnataka, India', 'Koramangala 4 Block, Koramangala, Bengaluru, Karnataka, India', 'Koramangala 4 Block, Koramangala, Bengaluru, Karnataka, India', 'India', 'uploads/1.jpg', '1', 'superadmin@prabaweb.com', '', '', 'SUPERADMIN', ''),
(37, 'praba', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'MEDICAL', 'prabakaran', 'p', 'Male', '23', 'praba@prabaweb.in', '8897464647', '6666', '66', 'Majestic, Bengaluru, Karnataka, India', 'Majestic, Bengaluru, Karnataka, India', 'Majestic, Bengaluru, Karnataka, India', 'India', 'uploads/3.jpg', '1', 'admin@gmail.com', 'admin medical', '', 'SUPERADMIN', ''),
(38, 'admin@praba.com', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'ADMIN', 'admin', 'p', 'Male', '25', 'admin@gmail.com', '9972396115', '8904655783', 'prabaweb', 'Koramangala 4 Block, Koramangala, Bengaluru, Karnataka, India', 'koramangala', 'koramanagala', 'India', 'uploads/Penguins.jpg', '1', 'superadmin@prabaweb.com', 'nammapharma', '', 'SUPERADMIN', '');

Edited by fireburner29: mistake

2
Contributors
7
Replies
25
Views
2 Years
Discussion Span
Last Post by fireburner29
0

I don't really get what you're asking here. What exactly is is that you want help with? Writing PHP to display records? Then you'd have to be a bit more specific about what information you want to display. So could you clear up your question a bit?

0

sorry for bad english
i given create access for superadmin and admin. if admin creates new users it has to display his(admin) account and superadmin account.
Meanwhile if superadmin creates new user, it has to display oly superadmin account. it should not display in admin account.
i wanted to write sql query for this.
so please help me.

thanks

Edited by fireburner29: mistake

0

Ok so let me first rephrase your answer so that I'm sure I understand it correctly.

What you want is:
(1) When an admin is logged in, he may only see users that are "admin".
(2) When a superadmin is logged in, he may see users that are either "admin" or "superadmin".

Is this correct?

Edited by minitauros

1

What about something like:

<?php
if ($user_role == 'superadmin') {
    // Select superadmin and admin users.
    $query = 'SELECT * FROM users WHERE role = "superadmin" OR role = "admin"';
}
elseif ($user_role =='admin') {
    // Select only admin users.
    $query = 'SELECT * FROM users WHERE role = "admin"';
}

// Execute the query

(This is just an example, you should of course fill in the var names and field names and table names you want to use).

Edited by minitauros

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.