{"id":12140,"date":"2019-10-22T00:00:00","date_gmt":"2019-10-21T16:00:00","guid":{"rendered":"https:\/\/fgchen.com\/wpedu2\/2019\/10\/22\/%e4%bd%bf%e7%94%a8jquery%e8%88%87php%e6%8a%93%e5%8f%96sql%e6%9f%a5%e8%a9%a2%e7%9a%84%e6%95%b4%e5%80%8b%e8%a1%a8%e6%a0%bc%e8%b3%87%e6%96%99%e9%99%a3%e5%88%97%e8%b3%87%e6%96%99\/"},"modified":"2026-03-30T14:41:21","modified_gmt":"2026-03-30T06:41:21","slug":"%e4%bd%bf%e7%94%a8jquery%e8%88%87php%e6%8a%93%e5%8f%96sql%e6%9f%a5%e8%a9%a2%e7%9a%84%e6%95%b4%e5%80%8b%e8%a1%a8%e6%a0%bc%e8%b3%87%e6%96%99%e9%99%a3%e5%88%97%e8%b3%87%e6%96%99","status":"publish","type":"post","link":"https:\/\/fgchen.com\/wpedu\/2019\/10\/%e4%bd%bf%e7%94%a8jquery%e8%88%87php%e6%8a%93%e5%8f%96sql%e6%9f%a5%e8%a9%a2%e7%9a%84%e6%95%b4%e5%80%8b%e8%a1%a8%e6%a0%bc%e8%b3%87%e6%96%99%e9%99%a3%e5%88%97%e8%b3%87%e6%96%99\/","title":{"rendered":"\u4f7f\u7528jQuery\u8207PHP\u6293\u53d6SQL\u67e5\u8a62\u7684\u6574\u500b\u8868\u683c\u8cc7\u6599(\u9663\u5217\u8cc7\u6599)"},"content":{"rendered":"\u9019\u7bc7\u6587\u7ae0\u4fc2\u5354\u52a9\u5c08\u984c\u751f\u5f8c\u6574\u7406\u7522\u751f\u3002\nJavaScript\/HTML\u7aef\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">&lt;script type=\"text\/javascript\"&gt;\n  tableBody = $(\"table tbody\")\n  $.post('b1.php',\n    function(data) { \/\/\u5f9e\u5f8c\u7aef\u50b3\u5165\u8cc7\u6599\u5eab\u67e5\u8a62\u7684\u8cc7\u6599\u9663\u5217\n      var result = $.parseJSON(data);  \/\/\u4ee5json\u683c\u5f0f\u6316\u51fadata\u9663\u5217\u88cf\u7684\u8cc7\u6599\n      $.each( result, function( key, value ) { \/\/\u628a\u9663\u5217\u88cf\u7684\u8cc7\u6599\u4e00\u7b46\u4e00\u7b46\u2026\n        var str = \"&lt;tr&gt;&lt;td&gt;\" + value['tabletime'] + \"&lt;\/td&gt;\" +\n               \"&lt;td&gt;\" + value['detail'] + \"&lt;\/td&gt;\" +\n               \"&lt;td&gt;\" + value['oktime'] + \"&lt;\/td&gt;\" +\n               \"&lt;td&gt;&lt;button type='button' class='de' data-detail='\" + value['detail'] + \"' data-tabletime='\" + value['tabletime'] + \"' id='ID' onclick='setFinished(this)'&gt;\u5b8c\u6210&lt;\/button&gt;&lt;\/td&gt;&lt;\/tr&gt;\";\n        tableBody.append(str);\n      });\n      \/\/ console.log($('.bell_table').html());\n    });\n  function setFinished(elm){\n    \/\/ console.log($(this).data(\"detail\"));\n    \/\/ console.log($(this).data(\"tabletime\"));\n    console.log(elm.dataset.detail); \/\/onclick='setFinished(this), this, elm\u53c3\u8003\u6708\u66c6\u7a0b\u5f0f\u88cf\u7684dayClicked\u51fd\u5f0f\n    console.log(elm.dataset.tabletime);\n  }\n&lt;\/script&gt;<\/pre>\n\nPHP\u7aef (\u53ea\u8655\u7406\u5f8c\u7aef\u8cc7\u6599\u5eab\u7684\u6e9d\u901a)\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">$result_array = array();\n\/\/ Create connection\n$conn = new mysqli($servername, $username, $password, $dbname);\n\/\/ Check connection\nif ($conn-&gt;connect_error) {\n    die(\"Connection failed: \" . $conn-&gt;connect_error);\n}\n$sql = \"SELECT * FROM `bell`\";\n$result = $conn-&gt;query($sql);\nif ($result-&gt;num_rows &gt; 0) {\n  while($row = $result-&gt;fetch_assoc()) {\n    array_push($result_array, $row); \/\/\u5c07\u8cc7\u6599\u4e00\u7b46\u4e00\u7b46\u63a8\u5165\u8cc7\u6599\u9663\u5217\n  }\n  echo json_encode($result_array);\n} else {\n    echo \"0 results\";\n}\n$conn-&gt;close();<\/pre>\n\n&nbsp;","protected":false},"excerpt":{"rendered":"<p>\u9019\u7bc7\u6587\u7ae0\u4fc2\u5354\u52a9\u5c08\u984c\u751f\u5f8c\u6574\u7406\u7522\u751f\u3002 JavaScript\/HTML\u7aef &lt;sc &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[266],"tags":[],"class_list":["post-12140","post","type-post","status-publish","format-standard","hentry","category-266"],"_links":{"self":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/comments?post=12140"}],"version-history":[{"count":1,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12140\/revisions"}],"predecessor-version":[{"id":13630,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12140\/revisions\/13630"}],"wp:attachment":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/media?parent=12140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/categories?post=12140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/tags?post=12140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}