我正在一个项目中,该项目需要将多个列内容传递给php变量
我可以选择并将一列的内容传递给变量,但在多列上失败
$myEMPNEM = ""; $sqlNEM = "SELECT first_name, middle_name, last_name, job_title FROM t_employees WHERE user_name = '" . $_SESSION["uname"] . "'"; $resultNEM = mysqli_query( $conn, $sqlNEM ); while($row = mysqli_fetch_array($resultNEM)) { $myEMPNEM = $row['first_name']; }
我希望将不止一列内容传递给php变量
您要么需要将变量用作数组:
while($row = mysqli_fetch_array($resultNEM)) { $myEMPNEM = array($row['first_name'], $row['middle_name'], $row['last_name']); }
或将这些值连接到一个字符串中:
while($row = mysqli_fetch_array($resultNEM)) { $myEMPNEM = $row['first_name'] . " " . $row['middle_name'] . " " . $row['last_name']; }