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', '');

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?

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

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?

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.