从文件返回值(PHP)

时间:2017-10-22 18:52:42

标签: php mysql sql

我正在开发一个小网站。 我的第一个文件是我可以输入性别和类别的名称。

(等:Steven M Junior)

<!DOCTYPE  HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
    <head> 
        <meta  http-equiv="Content-Type" content="text/html;  charset=iso-8859-1"> 
        <title>Geef u borstnummer</title> 
    </head> 
    <p>
        <body> 
            <h3>Geef uw borstnummer in selecteer uw categorie en geslacht</h3> 
            <form  method="post" action="search.php?go"  id="searchform"> 
                <input  type="text" name="nummer">
                <select id="categorie" name="categorie">
                    <option value = "0"> Selecteer Categorie </option>
                    <option value = "B"> Benjamin </option>
                    <option value = "P"> Pupil </option>
                    <option value = "M"> Miniem </option>
                    <option value = "K"> Cadet </option>
                    <option value = "L"> Scholier </option>
                    <option value = "J"> Junior </option>
                    <option value = "S"> Senior </option>
                    <option value = "M"> Master </option>
                </select>
                <select id="geslacht" name="geslacht">
                    <option value = "0"> Selecteer geslacht </option>
                    <option value = "M"> Man </option>
                    <option value = "V"> Vrouw </option>
                </select>
                <input  type="submit" name="submit" value="Search"> 
            </form> 
        </body> 
    </p> 
</html> 

第二个文件使用这3个变量和$_POST方法,然后在mysql数据库中搜索它们。 此文件导出有关此人的更多信息。

(等:性别,姓名,类别,俱乐部,出生日期,编号)这些都存储在变量中。

(等:$Name$Category,...)

<?php
if(isset($_POST['submit']))
{
    if(isset($_GET['go']))
    {
        // if(preg_match("/^[0-9]*$/", $_POST['nummer']))
        // {
            $nummer_in=$_POST['nummer'];
            $categorie_in=$_POST['categorie'];
            $geslacht_in=$_POST['geslacht'];

            define('DB_NAME', 'atletiek');
            define('DB_USER', 'root');
            define('DB_PASSWORD', '');
            define('DB_HOST', 'localhost');

            $db=mysqli_connect  (DB_HOST, DB_USER,  DB_PASSWORD) or die ('I cannot connect to the database because: ' . mysqli_error());

            $mydb = mysqli_select_db($db, "atletiek");

            $sql="SELECT * FROM `atleten` WHERE `Borstnr` = $nummer_in AND `Categorie` = '$categorie_in' AND `Geslacht` = '$geslacht_in' ";

            $result=mysqli_query($db, $sql);
            if (!$result)
            {
                printf("Error: %s\n", mysqli_error($db));
                exit();
            }

            while($row=mysqli_fetch_array($result)) 
            {
                $ID =$row['ID'];
                $Geslacht=$row['Geslacht'];
                $Naam = $row['Naam'];
                $Categorie = $row['Categorie'];
                $Club = $row['Club'];
                $GeboorteJ = $row['Geboortej'];
                $Nummer = $row['Borstnr'];

            }
        // }
    }
    else
    {
        echo  "Please enter a search query ";
    }
}
?>

现在我想制作第三个文件,在屏幕上输出这些值。 我怎么能这样做?

我听说过在文件的网址中使用锚点(?name=Steven)或类似的东西,但我不知道如何使用它,并且无法找到很多信息。

有人能帮助我吗?

2 个答案:

答案 0 :(得分:0)

您可以在同一个脚本中回显输出,从中获取数据库中的值,这样您的<div class="navigation"> <?php wp_nav_menu( array( 'theme_location' => 'primary', 'container' => false, 'menu_class' => 'navbar-nav' ) ); ?> <ul class="navbar-nav"> <li class="nav-item right-border active"> <div class="mask"></div> <a href="#" class="nav-link">HOME <span class="sr-only">(current)</span> </a> </li> 就像:

search.php

答案 1 :(得分:0)

尝试围绕你的部分......

$html = '
<table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Geslacht</th>
            <th>Naam</th>
            <th>Categorie</th>
            <th>Club</th>
            <th>Geboortej</th>
            <th>Borstnr</th>
        </tr>
    </thead>
    <tbody>';
while($row=mysqli_fetch_array($result)) 
{
    $ID =$row['ID'];
    $Geslacht=$row['Geslacht'];
    $Naam = $row['Naam'];
    $Categorie = $row['Categorie'];
    $Club = $row['Club'];
    $GeboorteJ = $row['Geboortej'];
    $Nummer = $row['Borstnr'];

    $html .= '
    <tr>
        <td>'.$ID.'</td>
        <td>'.$Geslacht.'</td>
        <td>'.$Naam'.</td>
        <td>'.$Categorie.'</td>
        <td>'.$Club.'</td>
        <td>'.$GeboorteJ.'</td>
        <td>'.$Nummer.'</td>
    </tr>';
}
$html .= '<tbody></table>';