返回mysql结果并在另一个函数中使用
I have a php function that gets a users ID based on their studentid.
function getID() {
require "connect.php";
$id = mysqli_query($connection, "SELECT id, studentid FROM users
WHERE studentid = '".$_SESSION["studentid"]."'") or die(mysqli_error($connection));
$userID = mysqli_fetch_assoc($id);
echo $userID['id']; // Just to make sure it works
}
I would like to use the result of this function in another function but dont know how.
I would specifically like to use it in a where clause , e.g:
WHERE id = getID());
我有一个php函数,根据他们的studentntid获取用户ID。 p>
我想在另一个函数中使用此函数的结果,但不知道如何。 p>
我特别想在where子句中使用它,例如: p>
function getID(){
require“connect.php”;
$ id = mysqli_query($ connection,“SELECT id,studentid FROM users
WHERE studentid ='”。$ _ SESSION [“studentid “]。”'“或死(mysqli_error($ connection));
$ userID = mysqli_fetch_assoc($ id);
echo $ userID ['id']; //只是为了确保它正常工作
}
code> pre>
WHERE id = getID());
code > pre>
div>
Return $userID in you getId() function, and call the function when you build the query :
mysqli_query($connection, "SELECT id FROM table
WHERE id = '".getId()."'");