我有这个代码,我得到了一个网站,它在分页和搜索工作。我想要的是将一个图标或按钮添加到将链接到数据表中选定的特定数据的编辑和删除功能的列。如何使用php在一列中添加编辑和删除按钮?
/* Database connection start */
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "sample";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
/* Database connection end */
// storing request (ie, get/post) global array to a variable
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
\t 0 =>'id',
\t 1 => 'facility',
\t 2=> 'price',
\t 3=> 'action'
\t
);
// getting total number records without any search
$sql = "SELECT id, facility, price ";
$sql.=" FROM facilities";
$query=mysqli_query($conn, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql = "SELECT id, facility, price ";
$sql.=" FROM facilities WHERE 1=1";
if(!empty($requestData['search']['value'])) { // if there is a search parameter, $requestData['search']['value'] contains search parameter
\t $sql.=" AND (id LIKE '".$requestData['search']['value']."%' ";
\t $sql.=" OR facility LIKE '".$requestData['search']['value']."%' ";
\t $sql.=" OR price LIKE '".$requestData['search']['value']."%')";
}
$query=mysqli_query($conn, $sql);
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */ \t
$query=mysqli_query($conn, $sql);
$data = array();
while($row=mysqli_fetch_array($query)) { // preparing an array
\t $nestedData=array();
\t $nestedData[] = $row["id"];
\t $nestedData[] = $row["facility"];
\t $nestedData[] = $row["price"];
\t $nestedData[] = $row["id"];
\t
\t
\t $data[] = $nestedData;
}
$json_data = array(
\t \t \t "draw" => intval($requestData['draw']), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
\t \t \t "recordsTotal" => intval($totalData), // total number of records
\t \t \t "recordsFiltered" => intval($totalFiltered), // total number of records after searching, if there is no searching then totalFiltered = totalData
\t \t \t "data" => $data // total data array
\t \t \t);
echo json_encode($json_data); // send data as json format
?>
我在上面的代码,这部分有问题,我不知道我应该怎么放,这样它会为编辑工作,并删除图标/按钮..
$ nestedData [] = $ row [“id”]; - 用这个,它显示设施的id,我希望它是连接到我想要执行的功能的两个图标/按钮。
+0
试试这个为你的JSON: 版本PHP <= 5.4.0应该把: 定义('JSON_UNESCAPED_UNICODE')或定义('JSON_UNESCAPED_UNICODE',256); json_encode($ json_data,JSON_UNESCAPED_UNICODE); –
+0
你可以简单地用Ajax来完成。 [检查此链接](https://stackoverflow.com/a/19323136/7189547) –