Environment: Php5.6+mysql+apache
Back-End Code:
<?PHP//header (' Content-type:text/json;charset=utf-8 '); $con=Mysqli_connect("Database Address: Port", "User name", "Password", "Database name"); if(!$con) { die("Connection error:".)Mysqli_connect_error()); }Else{ EchoSuccess; }$action=$_get[' Action '];Switch($action) { Case' Del_row ':Del_row ();//Delete Break; Case' Edit_row ':Edit_row ();//Enquiry Break;}functionDel_row () {Global $con; $dataid=$_post[' Dataid ']; $sql= "Delete from ' order ' where ' id ' = '".$dataid."‘"; if(Mysqli_query($con,$sql)) { Echo' OK '; }Else{ Echo' Delete Failed '; }}functionEdit_row () {Global $con; $sql= "SELECT ID, Name, mobile from ' user_address '";//SQL query Statements $result=$con->query ($sql);//Get query Results if($result->num_rows > 0) { //output per row of data while($row=$result-Fetch_assoc ()) { $results[] =$row; } } Else { Echo"0 Results"; } EchoJson_encode ($results);}?>
Front-end Code
$.ajax ({type:"GET", URL:"./data.php?action=edit_row", Data:‘‘, DataType:"JSON", Success:function(data) {varLen =data.length, str= ' ', item; if(len>0) { for(vari = 0; i < Len; i++) {Item=Data[i]; STR+ = ' <tr> ' + ' <td> ' + item.id + ' </td> ' + ' <td> ' + it Em.name + ' </td> ' + ' <td> ' + item.mobile + ' </td> ' + ' < Td> ' + item.city + ' </td> ' + ' <td> ' + item.country + ' </td> ' + ' <td> ' + item.detail + ' </td> ' + ' <td> ' + ' <span class= ' order-btn ' > ' + ' delete ' + ' </span> ' + ' </td> ' + ' </tr> '; } $(' #order-table1 '). append (str); } } });
PHP implementation of simple query removal of MySQL