사람들이 데이터베이스에서 위치, 기간, 날짜 및 서비스의 네 가지 값을 검색 할 수있는 양식이 있습니다. 나는 항상 내가 원하는 결과를 얻지 못합니다.
AND를 사용하면 사람들이 모든 것을 채워야합니다. OR을 사용하면 완전한 데이터베이스를 얻습니다. 데이터베이스에서 1 ~ 4 개의 항목을 검색하고 싶습니다. 내가 이것을 할 수있는 방법이 있습니까?
어떤 필드가 채워져 있는지, 그리고 채워진 필드로 쿼리가 자동으로 변경되는지 확인하는 방법이 있습니까?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Zoeken</title>
</head>
<body>
<p><a href="new.php"><img src="add.png" width="20px" height="20px"/></a> | <a href="search.php"><img src="search.png" width="20px" height="20px"/></a> | <a href="search_lijnen.php"><img src="number.png" width="20px" height="20px"/></a> </p>
<form action="" method="post">
<div>
<table>
<tr><td><strong>Locatie: </strong></td><td><input type="text" name="Locatie" value="" /></td> </tr>
<tr><td><strong>Periode: </strong></td><td><input type="text" name="Periode" value="" /></td> </tr>
<tr><td><strong>Dag: </strong></td><td><input type="text" name="Dag" value="" /></td> </tr>
<tr><td><strong>Dienst: </strong></td> <td><input type="text" name="Dienst" value="" /></td></tr>
<tr><td></td><td><input type="submit" name="zoeken" value="Zoeken"></td></tr>
</table>
</div>
</form>
<p><a href="new.php"><img src="add.png" width="20px" height="20px"/></a> | <a href="search.php"><img src="search.png" width="20px" height="20px"/></a> | <a href="search_lijnen.php"><img src="number.png" width="20px" height="20px"/></a> </p>
</body>
</html>
<?php
if (isset($_POST['zoeken']))
{
include('connect-db.php');
$Locatie = $_POST['Locatie'];
$Periode = $_POST['Periode'];
$Dag = $_POST['Dag'];
$Dienst = $_POST['Dienst'];
// get results from database
$result = mysql_query("SELECT * FROM WMC_DeLijn WHERE Locatie='$Locatie' ANY Periode='$Periode' ANY Dag='$Dag'ANY Dienst='$Dienst' ")
or die(mysql_error());
// display data in table
echo "<h2>Resultaten:</h2><p>";
echo "<table border='1' cellpadding='10'>";
echo "<table><tr><th>ID</th><th>Locatie</th><th>Periode</th><th>Dag</th><th>Dienst</th><th>Delen</th><th>Geleed</th><th>Start 1</th><th>Eind 1</th><th>Start 2</th><th>Eind 2</th><th>Lijnen</th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td align="center">' . $row['id'] . '</td>';
echo '<td align="center">' . $row['Locatie'] . '</td>';
echo '<td align="center">' . $row['Periode'] . '</td>';
echo '<td align="center">' . $row['Dag'] . '</td>';
echo '<td align="center">' . $row['Dienst'] . '</td>';
echo '<td align="center">' . $row['Delen'] . '</td>';
echo '<td align="center">' . $row['Geleed'] . '</td>';
echo '<td align="center">' . $row['Start1'] . '</td>';
echo '<td align="center">' . $row['Eind1'] . '</td>';
echo '<td align="center">' . $row['Start2'] . '</td>';
echo '<td align="center">' . $row['Eind2'] . '</td>';
echo '<td align="center">' . $row['Lijnen'] . '</td>';
//Link to edit record
echo '<td align="center"><a href="edit.php?id=' . $row['id'] . '"><img src="edit.png" width="20px" height="20px"/></a></td>';
// Link to delete record
echo '<td align="center"><a href="delete.php?id=' . $row['id'] . '"><img src="delete.png" width="20px" height="20px"/></a></td>';
//Link to Add Event to Google Calendar
echo '<td align="center"><a href="Add_Event.php?id=' . $row['id'] . '"><img src="proceed.png" width="20px" height="20px"/></a></td>';
echo "</tr>";
}}
// close table>
echo "</table>";
?>
쿼리 문자열을 동적으로 빌드하거나 WHERE
매개 변수가 거짓이 아닌 경우 에만 절 문을 추가하거나 다음과 같이 SQL 자체에 조건을 추가 할 수 있습니다 WHERE (col = ? OR '' = ?) AND (col2 = ? OR '' = ?)
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다