我在显示数据库表的2种情况下的筛选表时遇到问题。
在这里,我有一个正常的完全工作表,其中显示了所有内容(我的意思是表中的所有数据,没关系):
<?php include("konekcija.php");?>
<?php
global $connection;
?>
<html>
<head>
<meta charset="UTF-8">
<title align="center">Prikaz evidencije</title>
<?php include("home.php"); ?>
<div align="center" id="centar">
<input type="button" value="Štampaj evidenciju" class="btn btn-primary" onClick="document.location.href='print.php'" style="font-weight:bold;" />
</div>
<body>
<table width="1000" border="3" align="center" style="width:80%">
<caption style="text-align:center; font-width:bold; font-size:35px; text-align:center; font-weight:bold;">Pregled evidencije</caption>
<tr style="background-color: #1a909e !important; font-weight: bold ; color: white !important;" align="center"; >
<td>ID</td>
<td>Ime studenta</td>
<td>Prezime studenta</td>
<td>Br. Indeksa</td>
<td>Predmet</td>
<td>Kolokvijum Teorija</td>
<td>Kolokvijum Zadaci</td>
<td>Aktivnost</td>
<td>Prisustvo</td>
<td>Seminarski rad</td>
<td>Domaći rad</td>
<td>∑ Predisp. Obaveza</td>
<td id="heed">Obriši</td>
<td id="heed1">Ažuriraj</td>
</tr>
<?php
$ViewQuery="SELECT * FROM evid_record";
$Execute= mysqli_query($connection, $ViewQuery);
while($datarows=mysqli_fetch_array($Execute)){
$id=$datarows['id'];
$ime=$datarows['imes'];
$prezime=$datarows['prezimes'];
$indeksbr=$datarows['indeksbr'];
$predmet=$datarows['predmet'];
$teorija=$datarows['teorija'];
$zadaci=$datarows['zadaci'];
$akt=$datarows['akt'];
$pris=$datarows['pris'];
$semrad=$datarows['semrad'];
$domrad=$datarows['domrad'];
$ukupno=$datarows['ukupno'];
?>
<tr align="center" style="background-color: white !important" >
<td><?php echo $id?></td>
<td><?php echo $ime ?></td>
<td><?php echo $prezime?></td>
<td><?php echo $indeksbr?></td>
<td><?php echo $predmet?></td>
<td><?php echo $teorija?></td>
<td><?php echo $zadaci?></td>
<td><?php echo $akt?></td>
<td><?php echo $pris?></td>
<td><?php echo $semrad?></td>
<td><?php echo $domrad?></td>
<td><?php echo $ukupno?></td>
<!-- Delete.php?*Delete* pokazivac u brisipodatke.php tj preuzima radnju odavde isto i za azuriraj-->
<td><a id="heed3" href='brisistudente.php?Delete=<?php echo $id;?>'class='btn btn-danger'> Obriši <i class='fa fa-remove'aria-hidden='true' style="text-align:right"></i></a></td>
<td><a id="heed4" href='azurirajstudente.php?Update=<?php echo $id;?>'class='btn btn-success'> Ažuriraj <i class='fa fa-remove'aria-hidden='true' style="text-align:right"></i></a></td>
</tr>
<?php } ?>
</table>
<h2 style="text-align:center; color: #ed0404; font-size: 1.4em; font-weight: bold;" class="Sucsess"><?php echo @$_GET['Deleted']; ?></h2>
<h2 style="text-align:center; color: #ed0404; font-size: 1.4em; font-weight: bold;" class="Sucsess"><?php echo @$_GET['Updated']; ?></h2>
</body>
</html>
我需要另一个表,用户将在其中输入“ indeksbr”(id)和“ predmet”(主题-因为我的项目是学生的考试记录),并且在提交时,他们应该得到一个过滤后的表,其中仅包含与/有关的数据他们。
到目前为止,这是我用于过滤表的代码,但是在3个小时内我没有任何结果。
<?php include("konekcija.php");?>
<?php
global $connection;
?>
<html>
<head>
<meta charset="UTF-8">
<title align="center">Prikaz evidencije</title>
<?php include("studhome.php"); ?>
<!--<div align="center" id="centar">
<input type="button" value="Štampaj evidenciju" class="btn btn-primary" onClick="document.location.href='print.php'" style="font-weight:bold;" />
</div>-->
<body>
<table width="1000" border="3" align="center" style="width:80%">
<caption style="text-align:center; font-width:bold; font-size:35px; text-align:center; font-weight:bold;">Pregled evidencije</caption>
<tr style="background-color: #1a909e !important; font-weight: bold ; color: white !important;" align="center"; >
<td>ID</td>
<td>Ime studenta</td>
<td>Prezime studenta</td>
<td>Br. Indeksa</td>
<td>Predmet</td>
<td>Kolokvijum Teorija</td>
<td>Kolokvijum Zadaci</td>
<td>Aktivnost</td>
<td>Prisustvo</td>
<td>Seminarski rad</td>
<td>Domaći rad</td>
<td>∑ Predisp. Obaveza</td>
<!--<td id="heed">Obriši</td>
<td id="heed1">Ažuriraj</td>-->
</tr>
<?php
if(isset($_POST['submit'])){
$ViewQuery="SELECT * FROM evid_record WHERE (indeksbr = '$indeksbr' AND predmet = '$predmet')";
$Execute= mysqli_query($connection, $ViewQuery);
while($datarows=mysqli_fetch_array($Execute)){
$id=$datarows['id'];
$ime=$datarows['imes'];
$prezime=$datarows['prezimes'];
$indeksbr=$datarows['indeksbr'];
$predmet=$datarows['predmet'];
$teorija=$datarows['teorija'];
$zadaci=$datarows['zadaci'];
$akt=$datarows['akt'];
$pris=$datarows['pris'];
$semrad=$datarows['semrad'];
$domrad=$datarows['domrad'];
$ukupno=$datarows['ukupno'];
?>
<tr align="center" style="background-color: white !important" >
<td><?php echo $id?></td>
<td><?php echo $ime ?></td>
<td><?php echo $prezime?></td>
<td><?php echo $indeksbr?></td>
<td><?php echo $predmet?></td>
<td><?php echo $teorija?></td>
<td><?php echo $zadaci?></td>
<td><?php echo $akt?></td>
<td><?php echo $pris?></td>
<td><?php echo $semrad?></td>
<td><?php echo $domrad?></td>
<td><?php echo $ukupno?></td>
<!-- Delete.php?*Delete* pokazivac u brisipodatke.php tj preuzima radnju odavde isto i za azuriraj-->
</tr>
<?php } ?>
</table>
</body>
</html>
这是另一个.php,其中有用于过滤表的输入字段:
<?php include("konekcija.php");?>
<!doctype html>
<html lang=''>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<script src="script.js"></script>
<title>EPO - sistem</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" href="custom.css">
</head>
<link rel="stylesheet" href="styles.css">
<body>
<nav class="navbar" style="background-color:#1a909e;">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand heads" href="#">EPO - SISTEM</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a href="studhome.php" style="color:white;"><span class="glyphicon glyphicon-hand-right" style="color:white;"></span> <?php echo $_SESSION['sime']; ?> <?php echo $_SESSION['sprezime']; ?></a></li>
<li><a href="studview.php" style="color:white;"><span class="glyphicon glyphicon-inbox" style="color:white !important;"></span> Prikaz evidencije</a></li>
<!--<li><a href="print.php" style="color:white;"><span class="glyphicon glyphicon-print" style="color:white !important;"></span> Stampaj evidenciju</a></li>-->
<li><a href="logout.php" style="color:white;"><span class="glyphicon glyphicon-log-out" style="color:white;"></span> LogOut</a></li>
</ul>
</div>
<!--<li class="dash"><a href="#"><?php echo $_SESSION['semail']; ?></a></li>-->
<div class="container-fluid">
</nav>
<div align="center" id="centar">
<div class="col-md-12">
<div class="col-md-12">
<span class="FieldInfo">Broj indeksa: </span><br><input type="text" name="indeksbr" value=""><br>
</div>
<span class="FieldInfo">Predmet: <br>
<select name="predmet" id="skraceno" style="width:187px; height:28px;">
<option>Izaberite..</option>
<option value="
<?php
$ViewQuery="SELECT epredmet FROM evidall";
$Execute= mysqli_query($connection, $ViewQuery) or die(mysqli_error());
while($datarows=mysqli_fetch_array($Execute)){
$predmet= $datarows['predmet'];
echo "<option value=\"".$datarows['epredmet']."\">" . $datarows['epredmet'] . "</option>";
}
?>" ></option>
<br></select><br>
</div>
</div>
<div align="center" id="centar">
<div class="col-md-12">
<input type="submit" name="submit" id="submit" value="Učitaj" class="form-control" style="height:42px; width:250px">
</div>
</div>
<div id="typed_text" class="row sub_msg" style="text-align:center;"></div>
<script src="typed.js"></script>
<div class="footer">
<p id="fut">All rights reserved, Nikola Mandic ©</p>
</div>
</body>
最佳答案
当您查询"SELECT * FROM evid_record WHERE (indeksbr = '$indeksbr' AND predmet = '$predmet')";
时,没有什么是$ indeksbr和$ predmet变量的线索。
我认为您的意思是$ _POST ['indeksbr']和$ _POST ['predmet'];如果这些变量是您的表单发送的数据。