Php 在一个数组中组合两列数据有什么解决方案吗?
我有一个问题,我想使用数组将数据库中的Firstname和Lastname列显示为一个数据。 顺便说一句,我是新的数组代码。我试图浏览任何类似的结果,但无法找到解决方案。非常感谢任何能帮助我的事情。谢谢 这是我当前的代码:Php 在一个数组中组合两列数据有什么解决方案吗?,php,arrays,Php,Arrays,我有一个问题,我想使用数组将数据库中的Firstname和Lastname列显示为一个数据。 顺便说一句,我是新的数组代码。我试图浏览任何类似的结果,但无法找到解决方案。非常感谢任何能帮助我的事情。谢谢 这是我当前的代码: // DB table to use $table = 'tbl_employee'; // Table's primary key $primaryKey = 'id_ref'; // Array of database columns which should be
// DB table to use
$table = 'tbl_employee';
// Table's primary key
$primaryKey = 'id_ref';
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
array( 'db' => 'emp_id_no', 'dt' => 0 ),
//this is my problem!! I want to combine this two different column.
array( 'db' => 'emp_lname' . "" .'db' => 'emp_fname', 'dt' => 1 ),
array( 'db' => 'emp_dep', 'dt' => 2 ),
array( 'db' => 'emp_job_name', 'dt' => 3 ),
array( 'db' => 'emp_status', 'dt' => 4 ),
);
无需使用数组来连接
emp\u lname
和emp\u fname
,您就可以使用sql查询,从而加快处理过程并提高代码的可理解性
$fullName = SELECT
emp_fname,
emp_lname,
CONCAT(emp_fname, ' ', emp_lname) full_name
FROM
tbl_employee
ORDER BY
full_name;
这里我要做的是,从表中获取emp\u fname
和emp\u lname
,然后将其分配给名为fullName
的变量。因此,您可以在数组中使用此变量,而不是在数组中包含列
您可以使用此链接作为sql server中concat的额外参考:
希望这将帮助您解决问题。您好!谢谢你给我看。有人能帮我解决上面的问题吗。在其他信息中,我将其用于php事件中的服务器处理。谢谢