在php中加入编辑按钮功能,如何使用php在一列中添加编辑和删除按钮?

我有这个代码,我得到了一个网站,它在分页和搜索工作。我想要的是将一个图标或按钮添加到将链接到数据表中选定的特定数据的编辑和删除功能的列。如何使用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) –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值