sql >> データベース >  >> RDS >> Mysql

要素IDをPHP変数に取り込む方法

    これはあなたの質問のようなものです:jQueryを使用したajax投稿

    これをすべて1つのファイルにまとめたい場合(アクティブなファイルに投稿する場合)、一般的に必要なものは次のとおりです。

    <?php 
      // Place this at the top of your file
      if (isset($_POST['id'])) {
        $newID = $_POST['id'];  // You need to sanitize this before using in a query
    
        // Perform some db queries, etc here
    
        // Format a desired response (text, html, etc)
        $response = 'Format a response here';
    
        // This will return your formatted response to the $.post() call in jQuery 
        return print_r($response);
      }
    ?>
    
    <script type='text/javascript'>
      $(document).ready(function() {
        $('.myElement').click(function() {
          $.post(location.href, { id: $(this).attr('id') }, function(response) {
            // Inserts your chosen response into the page in 'response-content' DIV
            $('#response-content').html(response); // Can also use .text(), .append(), etc
          });
        });
      });
    </script>
    
    <span id="1" class="myElement"></span>
    <span id="2" class="myElement"></span>
    
    <div id='response-content'></div>
    

    ここから、クエリと応答、および応答で何をしたいかをカスタマイズできます。



    1. MySQL Workbench-スキーマはデータベースと同じものですか?

    2. PHP関数にSQLクエリを入れる

    3. 上級ユーザー向けのSQLServer2016での全文検索の実装

    4. Oracleの隠し機能