du548397507 2017-04-06 12:05
浏览 65

为什么我的搜索结果在搜索表单下不可见?

hoping somebody is able to help!

I have created a search form to enable a user to search for a specific assessment day using the name, date and the company it is for. The results of this search should appear below the form used to generate the search. However, at the moment, when the search button is selected the form just refreshes and does not show any results? Can anyone advise? Code below:

    <?php

if(isset($_GET['submit'])){

require_once 'connect.php';



if(isset($_GET['nameofassessmentday'])) {
if(isset($_GET['dateofassessmentday'])) {
if(isset($_GET['companyname'])) {



    $nameofassessmentday = $db-> real_escape_string($_GET['nameofassessmentday']);
    $dateofassessmentday = $db-> real_escape_string($_GET['dateofassessmentday']);
    $companyname = $db-> real_escape_string($_GET['companyname']);

    $query = $db->query ("
        SELECT Name, Company 
        FROM assessment_day_details
        WHERE Name LIKE '{$nameofassessmentday}'
        AND Company LIKE '{$companyname}'
        AND Date_of_Day = '{$dateofassessmentday}'
        ");

        }
    }
}
?>

<div class="result-count">
    Found <?php echo $query->num_rows; ?> results.
</div>

<?php

if($query-> num_rows) {
    while($r = $query->fetch_object())  {
?>      
        <div class="result">
            <a href="#"> <?php echo $r->Name; ?></a>
            <a href="#"> <?php echo $r->Company; ?></a>
        </div>
        <?php
        }
    }
?>

<!DOCTYPE html>
<html>
<head>
    <title>Assess Existing Assessment Day-Search</title>
    <link rel="stylesheet"  href="style.css">
</head>
<?php

include 'function.php';
}
?>



<body>
    <div id="form">
        <form method="get">
        <p>
        <label>Name of Assessment Day:</label>
            <input type="text" id="nameofassessmentday" name="nameofassessmentday"  required/>
            </p>
        <p>
        <label>Date of Assessment Day:</label>
            <input type="date" id="dateofassessmentday" name="dateofassessmentday" required />
            </p>
        <p>
        <label>Company Name :</label>
            <input type="text" id="companyname" name="companyname"  required/>
            </p>

        <p>
            <input type="submit" id="btn" value="Search"  />
            </p>

        </form>
    </div>

</body>

</html>

Also, just one additional question for future reference. Is there anyway I would be able to hyperlink a search result to go to a particular page?

Thanks in advance!

And as some further information, prior to trying to get the search results to show in the same webpage, I had the below two pages and it worked perfectly.

<!DOCTYPE html>
<html>
<head>
    <title>Assess Existing Assessment Day-Search</title>
    <link rel="stylesheet"  href="style.css">
</head>
    <?php

    include 'function.php';

    ?>



    <body>
        <div id="form">
            <form action="search.php" method="get">
            <p>
            <label>Name of Assessment Day:</label>
                <input type="text" id="nameofassessmentday" name="nameofassessmentday"  required/>
                </p>
            <p>
            <label>Date of Assessment Day:</label>
                <input type="date" id="dateofassessmentday" name="dateofassessmentday" required />
                </p>
            <p>
            <label>Company Name :</label>
                <input type="text" id="companyname" name="companyname"  required/>
                </p>

            <p>
                <input type="submit" id="btn" value="Search"  />
                </p>

            </form>
        </div>

    </body>

    </html>

    <?php

require_once 'connect.php'; 
include 'function.php';

if(isset($_GET['nameofassessmentday'])) {
if(isset($_GET['dateofassessmentday'])) {
if(isset($_GET['companyname'])) {



    $nameofassessmentday = $db-> real_escape_string($_GET['nameofassessmentday']);
    $dateofassessmentday = $db-> real_escape_string($_GET['dateofassessmentday']);
    $companyname = $db-> real_escape_string($_GET['companyname']);

    $query = $db->query ("
        SELECT Name, Company 
        FROM assessment_day_details
        WHERE Name LIKE '{$nameofassessmentday}'
        AND Company LIKE '{$companyname}'
        AND Date_of_Day = '{$dateofassessmentday}'
        ");

        }
    }
}
?>

<div class="result-count">
    Found <?php echo $query->num_rows; ?> results.
</div>

<?php

if($query-> num_rows) {
    while($r = $query->fetch_object())  {
?>      
        <div class="result">
            <a href="#"> <?php echo $r->Name; ?></a>
            <a href="#"> <?php echo $r->Company; ?></a>
        </div>
        <?php
        }
    }
?>
  • 写回答

1条回答 默认 最新

  • dosgy00204 2017-04-06 12:21
    关注

    you have to add '%' when you use LIKE in query check here https://www.w3schools.com/sql/sql_like.asp

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效