php實現的mysql的簡單查詢刪除

來源:互聯網
上載者:User

標籤:address   nec   app   blog   apache   for   log   type   echo   

環境:php5.6+mysql+Apache

後端代碼:

<?php     // header(‘Content-Type:text/json;charset=utf-8‘);    $con=mysqli_connect("資料庫地址:連接埠","使用者名稱","密碼","資料庫名");     if (!$con)     {         die("串連錯誤: " . mysqli_connect_error());     }else{        echo "成功";    }$action = $_GET[‘action‘];switch ($action) {    case ‘del_row‘:        del_row();//刪除        break;    case ‘edit_row‘:        edit_row();//查詢        break;}function del_row(){    global $con;    $dataid = $_POST[‘dataid‘];    $sql = "delete from `order` where `id`=‘".$dataid."‘";    if (mysqli_query($con,$sql)) {        echo ‘ok‘;    }else{        echo ‘刪除失敗‘;    }}function edit_row(){    global $con;    $sql = "SELECT id, name, mobile FROM `user_address`";//sql查詢語句    $result = $con->query($sql);//獲得查詢結果         if ($result->num_rows > 0) {        // 輸出每行資料        while($row = $result->fetch_assoc()) {            $results[] = $row;        }    } else {        echo "0 results";    }    echo json_encode($results);}?>

前端代碼

$.ajax({        type: "GET",        url: "./data.php?action=edit_row",        data: ‘‘,        dataType: "json",        success: function(data){            var len = data.length,                str = ‘‘, item;            if(len>0) {                for (var i = 0; i < len; i++) {                    item = data[i];                    str += ‘<tr>‘ +                        ‘<td>‘ + item.id + ‘</td>‘ +                        ‘<td>‘ + item.name + ‘</td>‘ +                        ‘<td>‘ + item.mobile + ‘</td>‘ +                        ‘<td>‘ + item.city + ‘</td>‘ +                        ‘<td>‘ + item.country + ‘</td>‘ +                        ‘<td>‘ + item.detail + ‘</td>‘ +                        ‘<td>‘ + ‘<span class="order-btn">‘+‘刪除‘+‘</span>‘ + ‘</td>‘ +                        ‘</tr>‘;                }                $(‘#order-table1‘).append(str);            }        }    });

 

php實現的mysql的簡單查詢刪除

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.