Php 我可以使用什么机制将结果集传输到另一个查看页面?

Php 我可以使用什么机制将结果集传输到另一个查看页面?,php,Php,如何将$rs传输到新页面resultdetails.php processenterpin.php if (mysqli_num_rows($result) > 0) { //query to fetch the concerned result $query = "select * from result_header where RegNo = $regnumber && d_level = $details && d_sem = $d_

如何将
$rs
传输到新页面resultdetails.php

processenterpin.php

if (mysqli_num_rows($result) > 0) {
    //query to fetch the concerned result
    $query = "select * from result_header where RegNo = $regnumber && d_level = $details && d_sem = $d_sem";
    $rs = mysqli_query($conn, $query);

    //find a way and send rs to a new page then vomit the resultset in that new page.
}
        <?php

        require_once('db.php');

        function process($conn){
        $sql = "SELECT * FROM result_header";
        $result = $conn->query($sql);

        return   $result;   

        }

        ?>
我知道关于会议。我想知道还有没有别的办法

在resultdetails.php中检索
$rs
,并使用while循环在那里打印它

while($row = mysqli_fetch_assoc($rs)){
    //
}

在您必须使用的文件中,只需在变量声明之后添加以下代码

正如@spacePhoenix所说的,始终使用事先准备好的语句

include('resultdetails.php')

比如:

$rs = "Test variable";

include('resultdetails.php');


现在在resultdetails.php文件中,您可以使用$rs变量。

您可以使用函数将结果从一个页面传递到另一个页面

第一步。创建db.php

      <?php 

      $servername = "localhost";
      $username = "root";
      $password = "root";
      $dbname = "test";

      // Create connection
      $conn = new mysqli($servername, $username, $password,$dbname);

      // Check connection
      if ($conn->connect_error) {
          die("Connection failed: " . $conn->connect_error);
      } 
      //echo "Connected successfully";

      ?>

第二步。创建processenterpin.php

if (mysqli_num_rows($result) > 0) {
    //query to fetch the concerned result
    $query = "select * from result_header where RegNo = $regnumber && d_level = $details && d_sem = $d_sem";
    $rs = mysqli_query($conn, $query);

    //find a way and send rs to a new page then vomit the resultset in that new page.
}
        <?php

        require_once('db.php');

        function process($conn){
        $sql = "SELECT * FROM result_header";
        $result = $conn->query($sql);

        return   $result;   

        }

        ?>

第三步。创建resultdetails.php

            <?php 

            require_once('processenterpin.php');

            $result=process($conn);

            if ($result->num_rows > 0) {
                    // output data of each row
                    while($row = $result->fetch_assoc()) {
                        echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
                    }
                } else {
                        echo "0 results";
                }
            ?>


查看该片段,查询似乎使用了用户提交的数据,因此容易受到SQL注入攻击。将数据插入查询时,始终使用准备好的语句,而不考虑数据的来源。如果要将用户重定向到需要结果的其他页面,请在这些页面上执行查询。如果您包含这些php文件,那么这不应该是一个问题(如果它们在同一范围内)。但是在你继续之前,你应该遵循前面的评论和建议,使用事先准备好的陈述。你的想法太棒了。我会像你们提到的那个样做好准备。非常感谢。