gpt4 book ai didi

PHP - 从 MySQL 查询获取字符串

转载 作者:行者123 更新时间:2023-11-29 13:00:09 24 4
gpt4 key购买 nike

我需要从查询中检索字符串,然后在另一个 SQL 查询中使用该字符串。

这就是我所拥有的,我正在检索当前登录用户的当前分支 ID:

$neededBranch = mysqli_query($con, "SELECT BranchNumber FROM Staff WHERE staffID = '".$_SESSION['username_login']."'");

然后我需要在这里使用所说的字符串,如下所示:

$result = mysqli_query($con, "INSERT INTO SomeTable (
blah,
blah,
)
VALUES ('".$SomeValue."',"
. " '".$_SESSION['username_login']."',"
. " '".$neededBranch."')");

现在,“. "'".$neededBranch."')");"不起作用,因为它需要一个字符串。

我的问题是:如何从第一个查询中实际获取所需的值并在第二个查询中使用它?我是 PHP 新手,对此一无所知。

最佳答案

获取您查询的数据:

$result= mysqli_query($con, $query);//query is the select stmt
$row = mysqli_fetch_assoc($result);
$neededBranch = $row['BranchNumber'];

关于PHP - 从 MySQL 查询获取字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23461695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com