问题描述
这绝对是一个新手问题,但是如果您能提供任何帮助,我将非常感激.
This is definately a novice question, but if you could be of any help i would be very grateful.
基本上,我正在建立一个数据库管理页面,它当然包括搜索功能.
Basically, i'm building a database management page, and it of course includes a search function.
因此,搜索表单看起来像这样
So, the search form looks something like this
<form name="name" function="search.php" method="get">
但是,每当我使用它时,我当然都会重定向到search.php.我想要的是一种在搜索结果的同一页面上显示结果的方法(比如index.php),而不必围绕search.php构建整个相同的页面
But, whenever i use it, i will of course get redirected to search.php. What i want is a way to display the results on the same page i did the search from (let's say index.php), without having to build an entire identical page around search.php
感谢您的回答.
推荐答案
在表单中使用隐藏字段指示表单已提交.
Use a hidden field in the form that indicates that the form has been submitted.
在表单页面中(例如index.php)
In your form page (e.g. index.php)
<form name="name" action="index.php" method="post">
{OTHER_FORM_FIELDS}
<input type="hidden" name="doSearch" value="1">
</form>
因此,在您的php代码中(可以在index.php页或包含的php脚本中)
So in your php code (could be in the index.php page or in a php script included)
<?php
if($_POST['doSearch']==1) {
//query database
//get results
} ?>
在您的index.php页面中
in your index.php page
<?php if($_POST['doSearch']) { //a search request was made display my search results ?>
HTML_CODE
<?php } ?>
这篇关于使用PHP搜索MySQL并在同一页面上显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!