KaFF Posted March 22, 2007 Share Posted March 22, 2007 Hi there, im in a bit of a pickle i am trying to display all users in a table on my website with the following code. The first part looks at the following querys <?php session_start(); if( (isset($_SESSION['userid']) =="") && (isset($_SESSION['secretaryid'])=="") && (isset($_SESSION['admin'])=="") ){ } require "connect.php"; extract($_GET); if ($_SESSION['userid'] != "") { $query = "select u.userno,u.userid,u.username,u.role,u.yearid,u.department,s.secname from users u, secretary s, usersec us where us.secretaryno = s.secretaryno and us.userno = u.userno and u.userid = '".$_SESSION['userid']."' order by u.userid, u.yearid"; } else { $query = "select u.userno,u.userid,u.username,u.role,u.yearid,u.department,s.secname from users u, secretary s, usersec us where us.secretaryno = s.secretaryno and us.userno = u.userno order by u.userid, u.yearid"; } $result = @mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); ?> Then the following code below filters the above query depending on whether the user has logged in as an admin role or standard user. <?php while($row=mysql_fetch_array($result)) { if (($row['userid'] == $_SESSION['userid']) || ($_SESSION['admin'] == 1)) { ?> <tr> <td style="text-transform: uppercase"><?=$row['userid']?></td> <td><?=$row['username']?></td> <td><?=$row['role']?></td> <td><?=$row['yearid']?></td> <td><?=$row['department']?></td> <td><?=$row['secname']?></td> <? if (($_SESSION['admin']) == "1") { ?> <td> <td width="32" bgcolor="#666666" title="Edit User Details"><a href="updateuserform.php?userno=<?=$row['userno']?>"><font color="#FFFFFF">[edit]</a></td> <td width="53" bgcolor="#666666" title="Delete User Details"><a href="deleteuser.php?userno=<?=$row['userno']?>&yearid=<?=$row['yearid']?>" onClick="return confirm('Are you sure you want to delete this User?');">[delete]</a></td> <? } ?> <?php $query2 = "select s.secretaryid, us.yearid from secretary s, usersec us, users u where us.userno = u.userno"; $result2 = @mysql_query($query2,$connection) or die ("Unable to perform query<br>$query2"); $count=mysql_num_rows($result2); if($count <=1){ echo "*"; } elseif($count >1){ $row = mysql_fetch_array($result2); } ?> <?php }}?> The strange thing is that if a standard user logs in then the information is displayed for that user. But if an admin user logs in it shows nothing. If anyone has any ideas it would really help me as its part of my dissertation that has gotta be in friday! ARGH! Cheers Kaff Quote Link to comment Share on other sites More sharing options...
btherl Posted March 22, 2007 Share Posted March 22, 2007 Does the admin has a user id? Quote Link to comment Share on other sites More sharing options...
KaFF Posted March 22, 2007 Author Share Posted March 22, 2007 Yes the admin has a user id. Basically admin is set up as a normal user but then is declared by 1 or null as to whether they have admin rights Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.