Jump to content

Different views for users groups


azziman

Recommended Posts

Hi there,

how would i be able to make different views of the information for user groups. For example:

The admin group will have full acess to the personal details of a student
Whereas the lecturers have  limited access to the student personal details, like certain fields are hidden / removed

any help will be appreciated as always  ;D
Link to comment
https://forums.phpfreaks.com/topic/23343-different-views-for-users-groups/
Share on other sites

ummm, oki i dont think what i wrote prior was very clear *silly me*

here is a small extract from some code im using

[code]<table width="550" border="0">
  <tr class="main">
    <td colspan="3" class="main">Student ID</td>
    <td colspan="3" class="main"><?php echo "$student_id" ?></td>
  </tr>
  <tr class="main">
    <td colspan="3" class="main">School Year</td>
    <td colspan="3"><select name="edit14" size="1" id="select2">
      <option value="">--Select--</option>
      <option value="7" <?php if ($student_year == '7'){ echo "selected"; } ?>>7</option>
      <option value="8" <?php if ($student_year == '8'){ echo "selected"; } ?>>8</option>
      <option value="9" <?php if ($student_year == '9'){ echo "selected"; } ?>>9</option>
      <option value="10" <?php if ($student_year == '10'){ echo "selected"; } ?>>10</option>
      <option value="11" <?php if ($student_year == '11'){ echo "selected"; } ?>>11</option>
      <option value="Unassigned" <?php if ($student_year == 'unassigned'){ echo "selected"; } ?>>unassigned</option>
    </select></td>
  </tr>
  <tr class="main">
    <td colspan="3" class="main">Forename:</td>
    <td colspan="3"><input type="text" name="edit" value='<?php echo "$student_forename" ?>' /></td>
  </tr>
  <tr class="main">
    <td colspan="3" class="main">Surname:</td>
    <td colspan="3"><input type="text" name="edit1" value='<?php echo "$student_surname" ?>' /></td>
  </tr>
</table>[/code]

Now if i wanted to hide the student ID from all other users except the admin, is that possible without making new pages that are specific to that user group only.
if the student id is in a session then this should work will show the admin the id of the student anyone else nothink.

[code]

<?php session_start();

//database information


$query="select * from admin where admin_id='$admin_id'";
$result=mysql_query($query);

if(mysql_num_rows($result)==1){

?>

<table width="550" border="0">
  <tr class="main">
    <td colspan="3" class="main">Student ID</td>
    <td colspan="3" class="main"><?php echo $student_id}else{ }; ?></td>
  </tr>
  <tr class="main">
    <td colspan="3" class="main">School Year</td>
    <td colspan="3"><select name="edit14" size="1" id="select2">
      <option value="">--Select--</option>
      <option value="7" <?php if ($student_year == '7'){ echo "selected"; } ?>>7</option>
      <option value="8" <?php if ($student_year == '8'){ echo "selected"; } ?>>8</option>
      <option value="9" <?php if ($student_year == '9'){ echo "selected"; } ?>>9</option>
      <option value="10" <?php if ($student_year == '10'){ echo "selected"; } ?>>10</option>
      <option value="11" <?php if ($student_year == '11'){ echo "selected"; } ?>>11</option>
      <option value="Unassigned" <?php if ($student_year == 'unassigned'){ echo "selected"; } ?>>unassigned</option>
    </select></td>
  </tr>
  <tr class="main">
    <td colspan="3" class="main">Forename:</td>
    <td colspan="3"><input type="text" name="edit" value='<?php echo "$student_forename" ?>' /></td>
  </tr>
  <tr class="main">
    <td colspan="3" class="main">Surname:</td>
    <td colspan="3"><input type="text" name="edit1" value='<?php echo "$student_surname" ?>' /></td>
  </tr>
</table>
[/code]
oki i understand what your code is doing, if the admin is not logged in then do not show the student id.

What im trying to do is now add the lecturer login table to the select statement:

[code] $query="select * from admin where admin_id='$admin_id'";[/code]

I read on the JOIN syntax but i dont think that is what i would need for this one.


I dont know joins but you can try this ok.

[code]


<?php session_start();

//database information

$query1="select * from lec where lec_id='$lec_id'";
$result1=mysql_query($query1);

if(mysql_num_rows($result1)==1){

$query2="select * from admin where admin_id='$admin_id'";
$result2=mysql_query($query2);

if(mysql_num_rows($result2)==1){

?>

<table width="550" border="0">
  <tr class="main">
    <td colspan="3" class="main">Student ID</td>
    <td colspan="3" class="main"><?php echo $student_id}}else{ }; ?></td>
  </tr>
  <tr class="main">
    <td colspan="3" class="main">School Year</td>
    <td colspan="3"><select name="edit14" size="1" id="select2">
      <option value="">--Select--</option>
      <option value="7" <?php if ($student_year == '7'){ echo "selected"; } ?>>7</option>
      <option value="8" <?php if ($student_year == '8'){ echo "selected"; } ?>>8</option>
      <option value="9" <?php if ($student_year == '9'){ echo "selected"; } ?>>9</option>
      <option value="10" <?php if ($student_year == '10'){ echo "selected"; } ?>>10</option>
      <option value="11" <?php if ($student_year == '11'){ echo "selected"; } ?>>11</option>
      <option value="Unassigned" <?php if ($student_year == 'unassigned'){ echo "selected"; } ?>>unassigned</option>
    </select></td>
  </tr>
  <tr class="main">
    <td colspan="3" class="main">Forename:</td>
    <td colspan="3"><input type="text" name="edit" value='<?php echo "$student_forename" ?>' /></td>
  </tr>
  <tr class="main">
    <td colspan="3" class="main">Surname:</td>
    <td colspan="3"><input type="text" name="edit1" value='<?php echo "$student_surname" ?>' /></td>
  </tr>
</table>

[/code]
[code]-- --------------------------------------------------------

--
-- Table structure for table `admin`
--

CREATE TABLE `admin` (
  `admin_id` int(25) NOT NULL auto_increment,
  `username` varchar(25) NOT NULL default '',
  `password` varchar(100) NOT NULL default '',
  `email_address` varchar(250) NOT NULL default '',
  PRIMARY KEY  (`admin_id`)
) TYPE=MyISAM COMMENT='Admin Users' AUTO_INCREMENT=4 ;

--
-- Dumping data for table `admin`
--

INSERT INTO `admin` VALUES (1, 'admin1', 'c56594001e03e8ccb5870e0e2df5c0e7', '[email protected]');
INSERT INTO `admin` VALUES (2, 'admin2', 'cbb2d5a9b5e6e8421452bbbdfd01034f', '[email protected]');


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

--
-- Table structure for table `lecturer`
--

CREATE TABLE `lecturer` (
  `lecturer_id` int(25) NOT NULL auto_increment,
  `username` varchar(25) NOT NULL default '',
  `password` varchar(100) NOT NULL default '',
  `email_address` varchar(250) NOT NULL default '',
  PRIMARY KEY  (`lecturer_id`)
) TYPE=MyISAM COMMENT='Lecturer Users' AUTO_INCREMENT=4 ;

--
-- Dumping data for table `lecturer`
--

INSERT INTO `lecturer` VALUES (1, 'lect1', 'dsfsafsgsgsgre4534536546yy5454gh', '[email protected]');
INSERT INTO `lecturer` VALUES (2, 'lect2', 'dfhsky76764krhg43br43r43y88703hn', '[email protected]');

[/code]

oki thats the database, and yup your solution does work :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.