[英]After submitting a form (to filter content), the table of results appear on the same page. How do I do that?
I would like to ask for some advice on how to go about coding (with regards to my problem). 我想就如何进行编码(关于我的问题)提出一些建议。
Anyways, I have a search form which has a select form and a text box. 无论如何,我有一个搜索表单,其中包含一个选择表单和一个文本框。 After submitting, a table appears based on the filtered results from the form. 提交后,将根据表单中的筛选结果显示一个表格。
Do I have to use a session or do I just need to have $_POST variables in my php code? 我是否必须使用会话或者我只需要在我的PHP代码中使用$ _POST变量? Or is it javascript? 或者是javascript?
If it's $_POST or $_SESSION, do I need to create another php file? 如果是$ _POST或$ _SESSION,我是否需要创建另一个php文件? I've done that but it displays a lot of errors on my form page. 我已经这样做了,但它在我的表单页面上显示了很多错误。
I want the table to appear on the same page. 我希望表格出现在同一页面上。
My form 我的表格
<div class="form-group">
Find
<select name="selected" class="form-control" required data-error="Please select from the list">
<option value="">--Select--</option>
<option value="story">Stories</option>
<option value="poem">Poems</option>
<option value="user">Users</option>
</select>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
With
<input type="text" class="form-control" id="contains" name="contains" required
data-error="Please enter a value"/>
<div class="help-block with-errors"></div>
</div>
<div class="col-md-6 col-xs-6">
<input type="submit" class="btn btn-primary btn-block" id="submitBtn"
value="Search"/></div>
<div class="col-md-6 col-xs-6">
<input type="reset" class="btn btn-default btn-block" value="Clear Fields"/></div>
</form>
I've created a separate php file to store all my $_SESSIONS and $_POST but not really sure to go about it. 我已经创建了一个单独的php文件来存储我所有的$ _SESSIONS和$ _POST,但不是很确定。
<?php
session_start();
include("dbconn.php");
$selected = $_POST['selected'];
$searchContent = $_POST['content'];
$_SESSION['selected'] = $selected;
$_SESSION['contains'] = $searchContent;
if ($selected == "story" || $selected == "poem") {
if (isset($_SESSION['username'])) {
$querySearchSP = "select * from storypoem where content like '%$searchContent%' and type='poem'";
} else if (!isset($_SESSION['username'])) {
$querySearchSP = "select * from storypoem where content like '%$searchContent%' and type='poem' and progress='Completed'";
}
$resultSearchSP = mysqli_query($link, $querySearchSP);
$searchResultSP = mysqli_num_rows($resultSearchSP);
while ($rowStoryPoem = mysqli_fetch_array($searchResultSP)) {
$arrStoryPoem[] = $rowStoryPoem;
$_SESSION['title'] = $rowStoryPoem['title'];
$_SESSION['progress'] = $rowStoryPoem['progress'];
$_SESSION['currentlyCompleted'] = $rowStoryPoem['currentlycompleted'];
}
} else if ($selected == "user") {
$querySearchUser = "select * from user u, storypoem sp where content like '%$searchContent%' and u.storypoem_id=sp.id";
$resultSearchUser = mysqli_query($link, $querySearchUser);
$searchResultUser = mysqli_num_rows($resultSearchUser);
while ($rowUser = mysqli_fetch_array($searchResultUser)) {
$arrUser[] = $rowUser;
$_SESSION['username'] = $rowUser['username'];
$_SESSION['works'] = $rowStoryPoem['title'];
}
}
?>
Your help is much appreciated. 非常感谢您的帮助。 Thanks. 谢谢。
For same page follow this approach: 对于同一页面,请遵循以下方法
<form action="" name="frm">
// your html elements
<input type="submit" name="btn" value="Search" />
</form>
<?php
if(isset($_REQUEST['btn']))
{
// put your mysql code here and for that response create a result table by using looping on the result set
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.