简体   繁体   English

提交表单(过滤内容)后,结果表将显示在同一页面上。 我怎么做?

[英]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.

相关问题 提交后如何让表单值出现在表格中? - How can I get the form values to appear in the table after submitting? 在 html 中提交表格后如何在同一页面上显示表格? - How to show the table on same page after submitting the form in html? 提交联系表格后如何到达页面上的特定位置? - How do I get to a specific location on page after submitting contact form? 提交表单后如何清除之前的文本字段值而不刷新整个页面? - How do I clear the previous text field value after submitting the form with out refreshing the entire page? 提交发帖请求并点击另一个发帖请求后,我如何留在同一页面上? - How do I stay on the same page after submitting a post request and hit another post request? 提交到同一页面后如何重定向表单? - How do I redirect a form after submission to the same page? 我如何阻止用户在 React 上提交相同的表单 - how do i stop users from submitting the same form on react 提交表单时如何防止页面重置 - How do I prevent the page from resetting when submitting form 提交表单 Angular 后如何显示用户名 - How do I display the username after submitting the form Angular 提交后如何重新加载、清除或重定向 PHPmailer 表单? - How do I reload, clear or redirect a PHPmailer form after submitting?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM