PHP - 从MySQL Query获取字符串

PHP  - 从MySQL Query获取字符串

问题描述:

I need to retrieve a string from a query and then use that later on in another SQL query.

This is what I have, I'm retrieving the current branch ID for the currently logged in user:

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

And then I need to use said string here like this:

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

Now, the ". " '".$neededBranch."')");" does not work because it is expecting a string.

My question is: How do I actually get the value I'm needing from the first query and use it in the second query? I'm new at PHP and don't have a clue.

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

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

  $ neededBranch = mysqli_query($ con,  “SELECT BranchNumber FROM Staff WHERE staffID ='”。$ _ SESSION ['username_login']。“'”); 
  code>  pre> 
 
 

然后我需要在这里使用所说的字符串 像这样: p>

  $ result = mysqli_query($ con,“INSERT INTO SomeTable(
 blah,
 blah,
)
 VALUES('”。$ SomeValue  。“',”
。“'”。$ _ SESSION ['username_login']。“',”
。“'”。$ neededBranch。“')”); 
  code>  pre>  
 
 

现在,“。”'“。$ neededBranch。”')“); code>”不起作用,因为它需要一个字符串。 p> \ n

我的问题是:如何从第一个查询中获得我需要的值并使用i 在第二个查询? 我是PHP的新手并且没有线索。 p> div>

Fetch the data you queried:

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