{"id":175197,"date":"2024-11-08T03:51:19","date_gmt":"2024-11-07T19:51:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/175197\/"},"modified":"2024-11-08T03:51:20","modified_gmt":"2024-11-07T19:51:20","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8datagrid%e7%8d%b2%e5%8f%96%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e6%9f%90%e4%b8%80%e8%a1%8c%e6%95%b8%e6%93%9a-datagrid-%e7%8d%b2%e5%8f%96%e6%9f%90%e4%b8%80","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/175197\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528datagrid\u7372\u53d6\u6578\u64da\u5eab\u4e2d\u7684\u67d0\u4e00\u884c\u6578\u64da (datagrid \u7372\u53d6\u67d0\u4e00\u884c\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8datagrid%e7%8d%b2%e5%8f%96%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e6%9f%90%e4%b8%80%e8%a1%8c%e6%95%b8%e6%93%9a-wsCabUmLbg\">\u5982\u4f55\u4f7f\u7528datagrid\u7372\u53d6\u6578\u64da\u5eab\u4e2d\u7684\u67d0\u4e00\u884c\u6578\u64da<\/h1>\n<p>\u5728\u73fe\u4ee3\u7684Web\u61c9\u7528\u7a0b\u5e8f\u4e2d\uff0c\u6578\u64da\u7684\u5c55\u793a\u548c\u64cd\u4f5c\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002datagrid\u4f5c\u70ba\u4e00\u7a2e\u5e38\u898b\u7684\u6578\u64da\u5c55\u793a\u5de5\u5177\uff0c\u80fd\u5920\u6709\u6548\u5730\u5c07\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u4ee5\u8868\u683c\u7684\u5f62\u5f0f\u5448\u73fe\u7d66\u7528\u6236\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528datagrid\u4f86\u7372\u53d6\u6578\u64da\u5eab\u4e2d\u7684\u67d0\u4e00\u884c\u6578\u64da\uff0c\u4e26\u63d0\u4f9b\u76f8\u95dc\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afdatagrid%ef%bc%9f-wsCabUmLbg\">\u4ec0\u9ebc\u662fdatagrid\uff1f<\/h2>\n<p>datagrid\u662f\u4e00\u7a2e\u7528\u65bc\u986f\u793a\u548c\u64cd\u4f5c\u6578\u64da\u7684\u63a7\u4ef6\uff0c\u901a\u5e38\u7528\u65bcWeb\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u5b83\u53ef\u4ee5\u986f\u793a\u4f86\u81ea\u6578\u64da\u5eab\u7684\u591a\u884c\u6578\u64da\uff0c\u4e26\u63d0\u4f9b\u6392\u5e8f\u3001\u904e\u6ffe\u548c\u7de8\u8f2f\u7b49\u529f\u80fd\u3002datagrid\u7684\u9748\u6d3b\u6027\u4f7f\u5176\u6210\u70ba\u958b\u767c\u8005\u5728\u69cb\u5efa\u7528\u6236\u754c\u9762\u6642\u7684\u9996\u9078\u5de5\u5177\u4e4b\u4e00\u3002<\/p>\n<h2 id=\"%e8%a8%ad%e7%bd%aedatagrid-wsCabUmLbg\">\u8a2d\u7f6edatagrid<\/h2>\n<p>\u5728\u4f7f\u7528datagrid\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u8a2d\u7f6e\u6578\u64da\u5eab\u9023\u63a5\u4e26\u7372\u53d6\u6578\u64da\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528PHP\u548cMySQL\u4f86\u8a2d\u7f6edatagrid\uff1a<\/p>\n<pre><code>\nconnect_error) {\n    die(\"Connection failed: \" . $conn-&gt;connect_error);\n}\n\n\/\/ \u7372\u53d6\u6578\u64da\n$sql = \"SELECT * FROM table_name\";\n$result = $conn-&gt;query($sql);\n?&gt;\n<\/code><\/pre>\n<h2 id=\"%e5%9c%a8datagrid%e4%b8%ad%e9%a1%af%e7%a4%ba%e6%95%b8%e6%93%9a-wsCabUmLbg\">\u5728datagrid\u4e2d\u986f\u793a\u6578\u64da<\/h2>\n<p>\u4e00\u65e6\u7372\u53d6\u4e86\u6578\u64da\uff0c\u5c31\u53ef\u4ee5\u5c07\u5176\u986f\u793a\u5728datagrid\u4e2d\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5728HTML\u4e2d\u5275\u5efa\u4e00\u500b\u7c21\u55ae\u7684datagrid\uff1a<\/p>\n<pre><code>\n<table border=\"1\">\n    <tr>\n        <th>ID<\/th>\n        <th>Name<\/th>\n        <th>Email<\/th>\n    <\/tr>\n    num_rows &gt; 0) {\n        \/\/ \u8f38\u51fa\u6578\u64da\n        while($row = $result-&gt;fetch_assoc()) {\n            echo \"<tr>\";\n            echo \"<td>\" . $row[\"id\"] . \"<\/td>\";\n            echo \"<td>\" . $row[\"name\"] . \"<\/td>\";\n            echo \"<td>\" . $row[\"email\"] . \"<\/td>\";\n            echo \"<\/tr>\";\n        }\n    } else {\n        echo \"0 results\";\n    }\n    $conn-&gt;close();\n    ?&gt;\n<\/table>\n<\/code><\/pre>\n<h2 id=\"%e7%8d%b2%e5%8f%96%e7%89%b9%e5%ae%9a%e8%a1%8c%e6%95%b8%e6%93%9a-wsCabUmLbg\">\u7372\u53d6\u7279\u5b9a\u884c\u6578\u64da<\/h2>\n<p>\u5982\u679c\u9700\u8981\u7372\u53d6datagrid\u4e2d\u7684\u67d0\u4e00\u884c\u6578\u64da\uff0c\u53ef\u4ee5\u901a\u904e\u6dfb\u52a0\u4e00\u500b\u4e8b\u4ef6\u4f86\u5be6\u73fe\u3002\u4f8b\u5982\uff0c\u7576\u7528\u6236\u9ede\u64ca\u67d0\u4e00\u884c\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528JavaScript\u4f86\u7372\u53d6\u8a72\u884c\u7684\u6578\u64da\uff1a<\/p>\n<pre><code>\n\n    function getRowData(row) {\n        var cells = row.getElementsByTagName(\"td\");\n        var id = cells[0].innerHTML;\n        var name = cells[1].innerHTML;\n        var email = cells[2].innerHTML;\n\n        alert(\"ID: \" + id + \"nName: \" + name + \"nEmail: \" + email);\n    }\n\n<\/code><\/pre>\n<p>\u5728HTML\u8868\u683c\u4e2d\uff0c\u53ef\u4ee5\u70ba\u6bcf\u4e00\u884c\u6dfb\u52a0onclick\u4e8b\u4ef6\uff1a<\/p>\n<pre><code>\n<tr>\n    <td>1<\/td>\n    <td>John Doe<\/td>\n    <td>john@example.com<\/td>\n<\/tr>\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-wsCabUmLbg\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528datagrid\u4f86\u7372\u53d6\u6578\u64da\u5eab\u4e2d\u7684\u67d0\u4e00\u884c\u6578\u64da\u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\u3002\u901a\u904e\u8a2d\u7f6e\u6578\u64da\u5eab\u9023\u63a5\u3001\u7372\u53d6\u6578\u64da\u4e26\u5728datagrid\u4e2d\u986f\u793a\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u5be6\u73fe\u6578\u64da\u7684\u5c55\u793a\u548c\u64cd\u4f5c\u3002\u7121\u8ad6\u662f\u7528\u65bc\u4f01\u696d\u61c9\u7528\u9084\u662f\u500b\u4eba\u9805\u76ee\uff0cdatagrid\u90fd\u80fd\u63d0\u4f9b\u9748\u6d3b\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684Web\u61c9\u7528\u7a0b\u5e8f\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528 DataGrid \u7372\u53d6\u6578\u64da\u5eab\u4e2d\u7279\u5b9a\u884c\u7684\u6578\u64da\uff0c\u7c21\u5316\u6578\u64da\u986f\u793a\u8207\u64cd\u4f5c\u904e\u7a0b\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-175197","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/175197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=175197"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/175197\/revisions"}],"predecessor-version":[{"id":175198,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/175197\/revisions\/175198"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=175197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=175197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=175197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}