Actually, I want to fetch data from my table according to the below condition, table contains 5 column, name, user_id, role, reporting_manager, password. I wrote one Html page for giving role.
<html>
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><!--Dquip--></title>
<link href="http://fonts.googleapis.com/css?family=Abel|Arvo" rel="stylesheet" type="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.dropotron-1.0.js"></script>
<script type="text/javascript" src="jquery.slidertron-1.0.js"></script>
<style>
label
{
display:inline-block;
width:150px;
margin-right:10px;
text-align:;
}
table,tr,th,td
{
border: 2px solid dodgerblue;
border-collapse: separate;
}
table
{
width:75%;
margin-top: 8%;
}
th,td
{
height: 50px;
}
td
{
text-align:center;
vertical-align: middle;
}
.button
{
width:75px;
height: 25px;
background-color:dodgerblue;
color:white;
border:1px solid transparent;
}
</style>
<center>
</head>
<body>
<h4 align="right"><a href="loginpage.php">Logout</a></h4>
<body>
<div id="wrapper">
<div id="header-wrapper">
<div id="header">
<div id="logo">
<h1><a href="#">Dquip..</a></h1>
</div>
</div>
<div id="menu-wrapper">
<ul id="menu">
<li class="current_page_item"><a href="calenderindex.html"><span>Homepage</span></a></li>
<li><span>Blog</span>
<ul>
<li class="first"> <a href="index">About US</a> </li>
<li> <a href="search">Function Area</a> </li>
<li class="last"> <a href="about">Contact US</a> </li>
</ul>
</li>
<li><a href="#"><span>Photos</span></a></li>
<li><a href="#"><span>About</span></a></li>
<li><span>Links</span>
<ul>
<li class="first"> <a href="index.php">Add Details</a> </li>
<li> <a href="map.php">Map view</a> </li>
<li class="last"> <a href="fetchinghome.php">view Details</a> </li>
</ul>
</li>
<li><a href="#"><span>Contact</span></a></li>
</ul>
<script type="text/javascript">
$('#menu').dropotron();
</script>
</div></br>
<h1><font color="white">Enter the dates to retrieve the data</font></h1></br></br>
<form method="POST" action="fetchinghome.php">
<label>Your user ID :</label><input type="text" name="role" placeholder="Enter the starting date">
<input type="submit" id="submit" name="submit" value="Go" class="button">
</form>
</body>
</html>
<?php
//include "loginpage.php";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if(isset($_POST['submit']))
{
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "calender";
$role=$_REQUEST['role'];
$conn = mysqli_connect($servername, $username, $password, $dbname);
if(! $conn )
{
die('Could not connect: ' . mysqli_error());
}
$sql="SELECT * FROM registration where reporting_manager='$role'";
$retval = mysqli_query( $conn,$sql );
if(! $retval )
{
die('Could not get data: ' . mysqli_error($conn));
}
echo "<table id='example' class='display' cellspacing='0' width='100%'>
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile Number</th>
<th>Address</th>
<th>Role</th>
<th>Action</th>
</tr>";
while($row = mysqli_fetch_array($retval))
{
echo "<tr><td>";
echo $row[0]."</td><td>";
echo $row[1]."</td><td>";
echo $row[2]."</td><td>";
echo $row[3]."</td><td>";
echo $row[4]."</td>";
echo "</tr>";
}
echo "</table>";
}
echo "Fetched data successfully
";
mysqli_close($conn);
}
?>
if i give role as admin, need to show all the data from the database. if i give role as manager1, then show the data of users whose reporting_manager is manger1 plus that manager1 person's details. and if i gave role as user1 fetch only that user details. is that possible to write this query in mysql using if else. if any one have any idea about this please tell me.