-4
사실, 아래 조건에 따라 테이블에서 데이터를 가져 오려고합니다. 테이블에 5 열, 이름, user_id, 역할, reporting_manager, 암호가 포함되어 있습니다. 나는 역할을 부여하기 위해 하나의 HTML 페이지를 썼다.mysql에서 쿼리를 가져 오는 중
<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\n";
mysqli_close($conn);
}
?>
관리자로 역할을 부여하면 데이터베이스의 모든 데이터를 표시해야합니다. manager1 역할을 부여한 경우 reporting_manager가 manger1이고 관리자 1 인의 세부 정보가있는 사용자의 데이터를 표시합니다. 그리고 user1로 역할을 부여하면 해당 사용자 세부 정보 만 가져옵니다. 은 else를 사용하여 mysql에서이 쿼리를 작성할 수 있습니다. 어떤 사람이 이것에 대해 어떤 생각을 갖고 있다면 말해주십시오.
당신은 질문에 대한 불필요한 코드, 단지 관련 한 ... –
ohk 포함되지 않도록해야한다 등의 조건. else 조건이있는 경우 SQL 쿼리를 사용하는 방법을 알고 있습니까? –