是否可以使用當前登錄用戶的登錄信息(即輸入的用戶名)來搜索與該用戶名關聯的表中的數據?我可能無法正確地問這個問題,但生病了,我一直在尋找關於如何使工作人員使用用戶名和密碼登錄並進入該頁面時使用他們的用戶名的信息查詢數據庫以找出哪個學校ID與該登錄相關,之後將生成針對該學校ID的應用列表。表「school_info」包含在該領域「schoolID」和用戶名掛在「用戶名」的學生證,表「EOI_AC_Data」包含字段「onlocal_schoolID_choice1」所申請學校的ID的,「onlocal_schoolID_choice2」和「onlocal_schoolID_cho ice3」。如果我沒有解釋得很好,這裏有一張截圖,希望能夠澄清關於桌子的事情。使用登錄詳細信息進行查詢?
http://i40.tinypic.com/2yn07l1.png
我已經寫了一些代碼,但基本上只是找回我想要顯示的數據,我真的不知道從哪裏開始就如何找回我想要顯示的具體數據,所以任何種類的幫助將非常有用。這裏是頁面本身的代碼:
<?php
require_once("nocache.php");
session_start();
$schoolID = $_SESSION["schoolID"];
$conn = mysqli_connect("localhost", "username", "password");
mysqli_select_db(twa312, $conn)
or die ('Database not found ' . mysqli_error());
$sql = "SELECT ApplicationID, given_name, family_name, dob, primary_school FROM EOI_AC_Data WHERE nonlocal_schoolID_choice2 = '$schoolID' order by dob";
$rs = mysqli_query($sql, $conn) or die ('Problem with query' . mysqli_error());
?>
<p><b>Listing of applications<b></p>
<?php while ($row = mysqli_fetch_array($rs)) { ?>
<p><a href="offerstatus.php?appid=<?php echo $row["ApplicationID"]?>">
<?php echo $row["ApplicationID"]?></a>
<?php echo $row["given_name"]?>
<?php echo $row["family_name"]?>
<?php echo $row["dob"]?>
<?php echo $row["primary_school"]?></p>
<?php } mysqli_close($conn); ?>
這裏是我的登錄頁面代碼:
<body>
<?php
require_once("nocache.php");
$id = $_POST["id"];
$pword = $_POST["pword"];
$msgp = "";
if(!empty($_POST)) {
if(!empty($id) && !empty($pword)) {
require_once("dbconn.php");
$sql = "select username, school_type, schoolID from school_info where username = '$id' and password = '$pword'";
$rs = mysqli_query($sql, $dbConn);
if(mysqli_num_rows($rs) > 0) {
session_start();
$_SESSION["who"] = $id;
$_SESSION["schoolID"] = mysql_result($rs, 0, "schoolID");
$_SESSION["school_type"] = mysqli_result($rs, 0, "school_type");
header("location: EOI_home.php");
}
} else {
header("location: login.php");
$msgp = '<span class="error>Incorrect username and/or password</span>';
}
}
?>
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"];?>" id="login">
<div id="menu-wrapper">
<div id="menu">
<ul>
<li><a href="EOI_home.php">Home</a></li>
</ul>
</div>
</div>
<div id="wrapper">
<div id="page">
<div id="page-bgtop">
<div id="page-bgbtm">
<h2>Enter Login Details</h2>
<div>
<p>Username: <input type="text" name="id" id="id" /></p>
<p>Password: <input type="password" name="pword" id="pword" /></p>
<input type="submit" value="log in" />
<input type="reset" />
</div>
</div>
</div>
</div>
</div>
</form>
對於這個問題還有比我明白的更多嗎?你爲什麼不使用where子句中的字段查詢eoi_ac_data表,就像你是school_info表一樣? –
你的意思是我爲什麼不按照我發佈的第二組代碼中的結構? – AJJ
我的意思是你爲什麼不以同樣的方式(用簡單的where子句)查詢與第一個表匹配的第二個表格行? –