Jump to content

Display All Users!


KaFF

Recommended Posts

Hi there,

 

I am trying to display all my users in a table using the

 

<?php
session_start();
if (isset($_SESSION['userid'])==false){
	header("Location: login.php");
	exit();
}
require "connect.php";
$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";
$result = @mysql_query($query, $connection)
	or die ("Unable to perform query<br>$query");
?>
<body>
<head>
<div align="right"> <img src="logo_tagline.gif">
<br>
<div align="left"><?php
$date=date("d-F-Y");
echo $date; 
?>
  </head>
  </div>
<table border="1" width="100%" height="38">
<tr>
    <td width="80%" bgcolor="#336600">	
    </td>
    <td width="20%" height="32" bgcolor="#336600">
      <div align="center" class="style2">
          <?=$_SESSION['username']?> Logged In</div>	
    </td>
</tr>
  </table>
  <table border="1" width="100%">
  <td width="80%">
  <h1 align="left">List all Users</h1>
  <table width="534" height="52" border="1" align="center">
	<tr>
		<th width="55">User ID</th>
		<th width="87">Username</th>
		<th width="52">Role</th>
		<th width="43">Year</th>
		<th width="104">Department</th>
		<th width="94">Secretary</th>
	</tr>
	<?php
		while($row=mysql_fetch_array($result))
	{
	?>
	<tr>
		<td><?=$row['USERID']?></td>
		<td><?=$row['USERNAME']?></td>
		<td><?=$row['ROLE']?></td>
		<td><?=$row['YEARID']?></td>
		<td><?=$row['DEPARTMENT']?></td>
		<td><?=$row['SECNAME']?></td>
		<td width="53" bgcolor="#669900"><a href="deleteuser.php?userno=<?=$row['USERNO']?>&yearid=<?=$row['YEARID']?>">[delete]</a></td>
	</tr>
	<?php } ?>
</table>
<div align="center"><a href="adduserform.php">Add New User<BR></a>
  <br>
      </div>
</td>
<td width="20%" bgcolor="#669900">
<br>
<p align="center"><a href="adduserform.php">Add User<BR></a>
    <a href="addsecretaryform.php">Add Secretary<BR><BR></a>
    <a href="updateuserform.php?userno=<?=$_SESSION['userno']?>">Update User<BR></a>
    <a href="updatesecretaryform.php?secretaryno=<?=$_SESSION['secretaryno']?>">Update Secretary<BR><BR></a>
    <a href="users.php">View All Users<BR></a>
    <a href="secretary.php">View All Secretaries<BR></a>
    <a href="bills.php">View All Bills<BR><BR></a>
</p>
</td>
<tr>
<td bgcolor="#666666"> </td>
<td bgcolor="#666666"><div align="center"><a href="logout.php">LOGOUT</a></div></td>
</table>
</tr>
</body>
</html>

 

The problem that i am having is that the query is displaying all the users but has repeated the data 3 times. I think i need to do some sort of if statement but im not sure where.

 

Any ideas would be greatly appreciated

 

KaFF

 

 

Link to comment
Share on other sites

$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";

You've provided no JOIN condition for the USERS table. How is table "USERS" related to SECRETARY and USERSEC?

Link to comment
Share on other sites

It might be your SQL statement. Can you run your SELECT statement in phpMyAdmin and see what it returns?

 

I think because you're using 3 tables, it will display the data based on all 3 tables so it looks like it is looping.  You only have 1 WHERE clause so it's not be specific enough from what table you want to display.

 

JOINing them might help too but I'm not great at joins to show you an example without too much tinkering.

 

Might at least point you in the right direction!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.