猿问

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

如何将转移$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.

}

我知道会议。我想知道是否还有另一种方法。


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


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

    //

}


白衣染霜花
浏览 162回答 2
2回答

jeck猫

您可以使用函数将结果一页传递到另一页。步骤1.创建db.php&nbsp; &nbsp; &nbsp; <?php&nbsp;&nbsp; &nbsp; &nbsp; $servername = "localhost";&nbsp; &nbsp; &nbsp; $username = "root";&nbsp; &nbsp; &nbsp; $password = "root";&nbsp; &nbsp; &nbsp; $dbname = "test";&nbsp; &nbsp; &nbsp; // Create connection&nbsp; &nbsp; &nbsp; $conn = new mysqli($servername, $username, $password,$dbname);&nbsp; &nbsp; &nbsp; // Check connection&nbsp; &nbsp; &nbsp; if ($conn->connect_error) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; die("Connection failed: " . $conn->connect_error);&nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp; //echo "Connected successfully";&nbsp; &nbsp; &nbsp; ?>步骤2.创建processenterpin.php&nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; require_once('db.php');&nbsp; &nbsp; &nbsp; &nbsp; function process($conn){&nbsp; &nbsp; &nbsp; &nbsp; $sql = "SELECT * FROM result_header";&nbsp; &nbsp; &nbsp; &nbsp; $result = $conn->query($sql);&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp; &nbsp;$result;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; ?>步骤3.创建resultdetails.php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; require_once('processenterpin.php');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $result=process($conn);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($result->num_rows > 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // output data of each row&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while($row = $result->fetch_assoc()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "0 results";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?>

元芳怎么了

您只需要在哪个文件中使用变量声明后添加以下代码即可。正如@spacePhoenix所说,始终使用准备好的语句。include('resultdetails.php');喜欢 :$rs = "Test variable";include('resultdetails.php');现在,在resultdetails.php文件中,可以使用$ rs变量。
随时随地看视频慕课网APP
我要回答