如何在单击搜索按钮并在同一页面上打印结果后同时保留搜索查询框和字母搜索
How to retain both the search query box and the alphabetical search after clicking on search button and printing result on the same page
我已经创建了我的PHP页面,我已经搜索了查询字段和按字母顺序搜索。提交查询后,我在同一页上打印结果。查询工作得很好,但我希望结果显示在相同的地方,我从字母搜索得到结果。即按字母顺序搜索是消失后,结果来自搜索框。如何在网页中同时保留它们?
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<input type="text" name="query" />
<input type="submit" value="Search" />
</form>
<?php
session_start();
$con=mysqli_connect("localhost","root","","journalskart"); /*Database Connection*/
//include('inc/search.php');
$errormsg= "No Record Found...!";
//search box script start from here
$alpha = $_GET['query'];
$min_length = 3;
if(strlen($alpha) >= $min_length){ // if query length is more or equal minimum length then
$alpha = htmlspecialchars($alpha);
// changes characters used in html to their equivalents, for example: < to >
$alpha = mysqli_real_escape_string($con, $alpha);
// makes sure nobody uses SQL injection
$q1 = mysqli_query($con,"SELECT * FROM vendor1
WHERE (title LIKE '%".$alpha."%') OR (publisher LIKE '%".$alpha."%')") or die(mysqli_error($con));
//$noofresult = mysqli_num_rows($q1);
//echo "$noofresult Result Found<br/>";
$num_rows=mysqli_num_rows($q1);
if($num_rows > 0)
{ // if one or more rows are returned do following
while($roww = mysqli_fetch_array($q1)){
$_SESSION["Title"] = $roww['title'];
$_SESSION["Fullset"] = $roww["full_set"];
$_SESSION["ISSN"] = $roww["issn"];
$_SESSION["Publisher"] = $roww["publisher"];
$_SESSION["Freq"] = $roww["freq"];
$_SESSION["Volume"] = $roww["volume"];
$_SESSION["Issue"] = $roww["issue"];
$_SESSION["Year"] = $roww["year"];
$_SESSION["Price"] = $roww["price"];
}
}
else{ // if there is no matching rows do following
echo "No results";
}
}//search box script end here
else{
$alpha="%";
if (isset($_REQUEST['alpha'])) {
$alpha = $_REQUEST['alpha']."%";
}
$q1 = mysqli_query($con, "select * from vendor1 where title like '$alpha%' " );
?>
<div >
<form action="" method="post" >
<table >
<tr>
<td>
<div style="float:left;">
<CENTER>
<FONT COLOR=Green>Sort by Alphabet:</FONT>
<A HREF="<?php echo $_SERVER['PHP_SELF']; ?>" >All</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=A">A</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=B">B</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=C">C</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=D">D</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=E">E</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=F">F</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=G">G</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=H">H</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=I">I</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=J">J</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=K">K</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=L">L</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=M">M</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=N">N</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=O">O</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=P">P</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=Q">Q</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=R">R</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=S">S</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=T">T</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=U">U</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=V">V</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=W">W</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=X">X</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=Y">Y</A>
<FONT COLOR=Green>|</FONT> <A HREF="?alpha=Z">Z</A>
</CENTER>
</div>
</td>
</tr>
<tr>
<th>Title</th>
<th>Full Set</th>
<th>ISSN</th>
<th>Publisher</th>
<th>Freq</th>
<th>Volume</th>
<th>Issue</th>
<th>Year</th>
<th>Price</th>
</tr>
<tbody>
<?php
$i=1;
$num_rows=mysqli_num_rows($q1);
if($num_rows==0)
{
?>
<div align="center">
<div class="alert alert-danger alert-dismissable">
<?php echo $errormsg; ?>
</div>
</div>
<?php
}
else
{
while($roww=mysqli_fetch_array($q1))
{
$_SESSION["Title"] = $roww['title'];
$_SESSION["Fullset"] = $roww["full_set"];
$_SESSION["ISSN"] = $roww["issn"];
$_SESSION["Publisher"] = $roww["publisher"];
$_SESSION["Freq"] = $roww["freq"];
$_SESSION["Volume"] = $roww["volume"];
$_SESSION["Issue"] = $roww["issue"];
$_SESSION["Year"] = $roww["year"];
$_SESSION["Price"] = $roww["price"];
?>
<tr>
<td>
<div style="height:100px;float:left;">
<input name="" type="checkbox" value="">
</div>
<div >
<a href="#"> <b><?php echo $_SESSION["Title"]; ?></b></a>
<td><?php echo $_SESSION["Fullset"]; ?></td>
<td><?php echo $_SESSION["ISSN"]; ?></td>
<td><?php echo $_SESSION["Publisher"]; ?></td>
<td><?php echo $_SESSION["Freq"]; ?></td>
<td><?php echo $_SESSION["Volume"]; ?></td>
<td><?php echo $_SESSION["Issue"]; ?></td>
<td><?php echo $_SESSION["Year"]; ?></td>
<td><?php echo $_SESSION["Price"]; ?></td>
</div></td>
</tr>
<?php }
$i++;
}
}
echo "$num_rows Results Found";
?>
</tbody>
</table>
</form>
</div>
</body></html>
<SCRIPT LANGUAGE=JavaScript>
<!--
document.write(ALPHABET())
//-->
</SCRIPT>
尝试使用基于条件的检查来查看是否进行了搜索
<?php
//general declarations
if ($_SERVER["REQUEST_METHOD"] == "GET") {
//body of your php code execution
}
?>php
<html>
//your html body
</html>
相关文章:
- 在字符串中传递_id和搜索查询
- 如何根据搜索查询更改着陆页
- 如何修改订阅上的搜索查询
- 我是否阅读了搜索查询中的所有推文
- 如何在php和javascript中使用regex检测空格分隔词(在全文搜索查询中)
- Javascript-来自关键字“;某事“;谷歌搜索查询“;什么的&”;
- 更改字符串中's已从搜索查询中返回
- 如何在Spotify中使用高级搜索查询
- 在谷歌地图上显示来自搜索查询的结果
- 为什么 js 和 html 代码没有运行搜索查询
- 如何对谷歌 API 搜索查询进行编码
- 如何在我的内容脚本中获取 Google 搜索查询字符串
- 使用 JSON 新闻 API 创建搜索查询
- 从 jQuery 中的 URL 中提取搜索查询
- JavaScript 在整个站点中持久化搜索查询
- 保存用户以前的搜索查询
- 搜索查询>填充下拉字段
- 如何在搜索查询中只排除#、$、%等特殊字符并包括字母表和数字
- 直接从PHP搜索查询链接到URL
- Mongodb搜索查询-返回所有结果(不匹配的)