我正在尝试使用我从ajax获取的变量使我的最后一行成为链接。
$(document).ready(function () {
var table = $('#example').DataTable({
paging: false,
"ajax": "includes/payroll.php",
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{"data": "empNum"},
{"data": "empName"},
{"data": "appFlag"},
{"data": "unitRate"},
{"data": "salary"},
{"data": "hourly"},
{
"defaultContent": '<?php echo '<a href=EmployeeInfo.php?empNum='.'data[0]'.'>Info</a>';?>'
}
],
"order": [[1, 'asc']]
});
我需要在php的链接中使用empNum,但我不知道如何将empNum元素放入我的php echo中。我已经尝试了mData和mRender,但它没有用,因为我认为我没有正确使用它们。
Array
(
[data] => Array
(
[0] => Array
(
[empNum] => 1
[empName] => SMITH, MARK E.
[unitRate] => 0
[salary] => 3282.84
[hourly] => 0
[appFlag] =>
[app1] => K002 1
[app2] =>
[app3] =>
[app4] =>
[app5] =>
[uni1] => .00
[uni2] => .00
[uni3] => .00
[uni4] => .00
[uni5] => .00
)
[1] => Array
(
[empNum] => 2
[empName] => SMITH, BRYANT J.
[unitRate] => 0
[salary] => 0
[hourly] => 800
[appFlag] =>
[app1] => 1E2
[app2] =>
[app3] =>
[app4] =>
[app5] =>
[uni1] => .00
[uni2] => .00
[uni3] => .00
[uni4] => .00
[uni5] => .00
)
[2] => Array
(
[empNum] => 4
[empName] => SMITH, JENNIFER L
[unitRate] => 0
[salary] => 1708.5
[hourly] => 0
[appFlag] =>
[app1] => 1A1
[app2] =>
[app3] =>
[app4] =>
[app5] =>
[uni1] => .00
[uni2] => .00
[uni3] => .00
[uni4] => .00
[uni5] => .00
)
这是payroll.php页面
<?php
include_once("dbconnect.php");
$types = array();
$connect = TRUE;
$dbconn = dbconnect($connect);
if ($dbconn) {
$sql = 'select dec(substr(hex(substr(f00001,1,3)),1,5),5,0),
cast(substr(f00001,7,25) as char(25) ccsid 37),
int(dec(substr(hex(substr(f00001,135,3)),1,5),5,0)),
double(dec((dec(substr(hex(substr(f00001,142,4)),1,7),7,0)/100),7,2)),
double(dec(substr(hex(substr(f00001,146,3)),1,5),5,0)),
cast(substr(f00001,679,1) as char(1) ccsid 37),
cast(substr(f00001,1421,13) as char(13) ccsid 37),
cast(substr(f00001,1434,13) as char(13) ccsid 37),
cast(substr(f00001,1447,13) as char(13) ccsid 37),
cast(substr(f00001,1460,13) as char(13) ccsid 37),
cast(substr(f00001,1473,13) as char(13) ccsid 37),
dec((dec(substr(hex(substr(f00001,1486,4)),1,7),7,0)/100),7,2),
dec((dec(substr(hex(substr(f00001,1490,4)),1,7),7,0)/100),7,2),
dec((dec(substr(hex(substr(f00001,1494,4)),1,7),7,0)/100),7,2),
dec((dec(substr(hex(substr(f00001,1498,4)),1,7),7,0)/100),7,2),
dec((dec(substr(hex(substr(f00001,1502,4)),1,7),7,0)/100),7,2)
from qs36f."PR.MST"
where dec(substr(hex(substr(f00001,5,2)),1,3),3,0) <>0';
$stmt = db2_prepare($dbconn, $sql);
if ($stmt) {
$result = db2_execute($stmt);
if (!$result) {
echo "execute errormsg: " . db2_stmt_errormsg($stmt);
}
while ($row = db2_fetch_array($stmt)) {
$load['data'][] = array(
'empNum' => $row[0],
'empName' => $row[1],
'unitRate' => $row[2],
'salary' => $row[3],
'hourly' => $row[4],
'appFlag' => $row[5],
'app1' => $row[6],
'app2' => $row[7],
'app3' => $row[8],
'app4' => $row[9],
'app5' => $row[10],
'uni1' => $row[11],
'uni2' => $row[12],
'uni3' => $row[13],
'uni4' => $row[14],
'uni5' => $row[15]
);
}
} else {
echo "execute errormsg: " . db2_stmt_errormsg($stmt);
}
db2_close($dbconn);
} else {
echo "faild " . db2_conn_errormsg();
}
$json = json_encode($load);
echo $json;
答案 0 :(得分:0)
看起来您对单引号和双引号的使用不正确。试试这个:
<?php echo '<a href= " EmployeeInfo.php?empNum=' . data[0] . ' ">Info</a>'; ?>
答案 1 :(得分:0)
render
就是您所需要的。 defaultContent
不了解数据,因此您无法分配变量。您也不需要使用PHP标记。
{
"render": function ( data, type, full, meta ) {
return '<a href= \'EmployeeInfo.php?empNum=' + full.empNum + '\'>Info</a>';
}
}