hi, i need to display the users under some admin. so i had written this code but it is not showing the required output. so can anyone...
do we need to add any function in this to get the username because by that username only we can know that he is admin.

<?php
ob_start();
$con=mysql_connect("10.70.1.50","invensis","invensis");
if(!$con)
	{
	 
		die('Could not connect: ' . mysql_error());
	}
mysql_select_db("database_myproject",$con);
$query= mysql_query("SELECT * FROM users where reportingto='$username'");
mysql_error();
$num=mysql_num_rows($query);
mysql_close($con);
 ?>
 <head>
<body>
 <table width="100%">
<tr><td> <img src="Logofinalcopy.gif">
</td></tr>
	<tr>
		<td bgcolor="aqua"><h2>Admin</h2></td>
	</tr></table>
	<tr>
			<td colspan="3"><?php include "Adminheader.php" ?></td>
	</tr>
	<div><table>
	<tr>			
		
		<td  align="right" style="width: 1000px">&nbsp;</td>
		
		<td  align="left" style="width: 177px"><a href="Admin.php" onclick="window.open('http://localhost/Project/usercreation.php','popup','width=550,height=400,scrollbars=no,resizable=no,toolbar=no,directories=no,location=center,menubar=no,status=no,left=370,center=0,top=300')">Add Users</a></td>
		
	</tr>
</table></div>

<table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
	<tr>
		<th>userid</th>
		<th>username</th>
		<th>password</th>
		<th>role</th>
		<th>status</th>
		<th>reportingto</th>   
	</tr>
<?php
$i=0;
while ($i < $num){
$f1=mysql_result($query,$i,"userid");
$f2=mysql_result($query,$i,"username");
$f3=mysql_result($query,$i,"password");
$f4=mysql_result($query,$i,"role");
if($f4 == 0)
   $f4 = 'Super Admin';
elseif($f4== 1)
   $f4 = 'Admin';
else
   $f4= 'User';   
$f5=mysql_result($query,$i,"status");
if($f5 == 1)
   $f5 = 'Active';
else
   $f5 = 'Inactive';
$f6=mysql_result($query,$i,"reportingto")
   ?>   
 <tr>
    
	<td><?php echo $f1;?></td>
	<td><?php echo $f2; ?></td>
	<td><?php echo $f3; ?></td>
	<td><?php echo $f4; ?></td>
	<td><?php echo $f5; ?></td>
    <td><?php echo $f6; ?></td>
	<td><a href =http://localhost/Project/Admin.php onclick="window.open('http://localhost/Project/update.php?f1=<?php echo $f1;?>','popup','width=550,height=400,scrollbars=no,resizable=no,toolbar=no,directories=no,location=center,menubar=no,status=no,left=370,center=0,top=300')">
    edit</a></td>
    <!--<td><input type="button" value="Edit" onclick="popup_show('popup', 'popup_drag', 'popup_exit', 'screen-center',0,0);" ></td> -->
</tr>
<?php
$i++;
}
?>
</table>
</body>
</head>

So basically, if I'm not mistaken you would like to create a dynamic table showing all of the users?

<?php
ob_start();
$con=mysql_connect("10.70.1.50","invensis","invensis");
if(!$con)
	{
	 
		die('Could not connect: ' . mysql_error());
	}
mysql_select_db("database_myproject",$con);
$query= mysql_query("SELECT * FROM users where reportingto='$username'");
echo '<table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
	<tr>
		<th>userid</th>
		<th>username</th>
		<th>password</th>
		<th>role</th>
		<th>status</th>
		<th>reportingto</th>   
	</tr>';

while($row = mysql_fetch_array($query))
{
    echo '<tr>';
    echo '<td align="left">' .$row['userid']. '</td>';
    echo '<td align="left">' .$row['username']. '</td>';
    echo '<td align="left">' .$row['password']. '</td>';
    echo '<td align="left">' .$row['role']. '</td>';
}
?>

Hope this helps!

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.