javascript - How to add edit and delete button in only one column using php? -
i have code got on site , works on pagination , search. want add icon or button column link edit , delete function specific data selected in datatable.
<?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 variable $requestdata= $_request; $columns = array( // datatable column index => database column name 0 =>'id', 1 => 'facility', 2=> 'price', 3=> 'action' ); // getting total number records without search $sql = "select id, facility, price "; $sql.=" facilities"; $query=mysqli_query($conn, $sql); $totaldata = mysqli_num_rows($query); $totalfiltered = $totaldata; // when there no search parameter total number rows = total number filtered rows. $sql = "select id, facility, price "; $sql.=" facilities 1=1"; if( !empty($requestdata['search']['value']) ) { // if there search parameter, $requestdata['search']['value'] contains search parameter $sql.=" , ( id '".$requestdata['search']['value']."%' "; $sql.=" or facility '".$requestdata['search']['value']."%' "; $sql.=" or price '".$requestdata['search']['value']."%' )"; } $query=mysqli_query($conn, $sql); $totalfiltered = mysqli_num_rows($query); // when there search parameter have modify total number filtered rows per search result. $sql.=" order ". $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 asc/desc */ $query=mysqli_query($conn, $sql); $data = array(); while( $row=mysqli_fetch_array($query) ) { // preparing array $nesteddata=array(); $nesteddata[] = $row["id"]; $nesteddata[] = $row["facility"]; $nesteddata[] = $row["price"]; $nesteddata[] = $row["id"]; $data[] = $nesteddata; } $json_data = array( "draw" => intval( $requestdata['draw'] ), // every request/draw clientside , send number parameter, when recieve response/data first check draw number, sending same number in draw. "recordstotal" => intval( $totaldata ), // total number of records "recordsfiltered" => intval( $totalfiltered ), // total number of records after searching, if there no searching totalfiltered = totaldata "data" => $data // total data array ); echo json_encode($json_data); // send data json format ?>
i having problem on part of code above, don't know should put work edit , delete icon/button..
$nesteddata[] = $row["id"]; - this, shows id of facility, want 2 icon/button link function want perform.
you can change $nesteddata[] = $row["id"];
to
$nesteddata[] = '<button type="button" class="btn btn-success" id="edit-'.$row["id"].'">edit</button> <button type="button" class="btn btn-danger" id="delete-'.$row["id"].'">delete</button>';
or
$nesteddata[] = '<a href="edit.php" class="btn btn-success" id="edit-'.$row["id"].'">edit</a> <button type="button" class="btn btn-danger" id="delete-'.$row["id"].'">delete</button>';
you can add tag, if want redirect edit page.
Comments
Post a Comment