如何将多列传递给php中的变量 [英] How to pass multiple columns to a variable in php
本文介绍了如何将多列传递给php中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个项目,该项目需要将多个列内容传递给php变量
I'm working on a project which requires more than one column contents to be passed to a php variable
我可以选择并将一列的内容传递给变量,但是在多列上失败
I am able to select and pass one column content to the variable but failed on multiple columns
$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变量
I expect more than one column content to be passed to the php variable
推荐答案
您要么需要将变量用作数组:
You either need to use the variable as an array:
while($row = mysqli_fetch_array($resultNEM))
{
$myEMPNEM = array($row['first_name'], $row['middle_name'], $row['last_name']);
}
或将这些值连接在一起成为一个字符串:
Or concatenate the values together into a single string:
while($row = mysqli_fetch_array($resultNEM))
{
$myEMPNEM = $row['first_name'] . " " . $row['middle_name'] . " " . $row['last_name'];
}
这篇关于如何将多列传递给php中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文