简体   繁体   中英

How can we make a particular value in sql row display its value on html table row and its updated value in next row in that table using php?

For Example,

Let us take in an sql table we have following things in a row:

  • username
  • password
  • payment amount

I have a form where I can type an amount to store in database and also it is stored in html table. when I type a different amount then it should be stored and new row should be added with this updated value in that table.

How to achieve this using php ?

You need to create this via ajax.

  1. Add ajax script with loop update every n sec.
  2. Create php page with content.

Call ajax every second and append result with message to div .js_messages .

HTML page with ajax:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
  <script
  src="https://code.jquery.com/jquery-2.2.4.min.js"
  integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
  crossorigin="anonymous"></script>
</head>
<body>
    <div class="js_messages"></div>
    <script type="text/javascript">
        function updateMessage() {
            var $messageContainer = $('.js_messages');

            $.ajax({
                type: "POST",
                url: "test.php",
                dataType: "json",
                success: function(data){
                    $messageContainer.append('<div class="js_messages-item">' + data.message + '</div>')
                },
            });
        }

        window.setInterval(function(){
          updateMessage()
        }, 1000);
    </script>
</body>
</html>

PHP page:

Just generate random message for example.

<?php

echo json_encode(['message' => mt_rand()]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM