title: Create button inside table and change while onclick event
body: <p>I have a problem creating a button on the fly within its function. I've created a table perfectly in <strong>php</strong> but I don't know how to create a button inside <strong>php</strong> code using a function on each button. </p>
  
  <pre><code>Example 
  ID              NAME            PRICE               ADD
  1               STRAW            100                BUTTON 1
  2               STRAWRE          300                BUTTON 2
  3               STRAWTO          200                BUTTON 3
  </code></pre>
  
  <p>The button add is dynamically using looping inside the <strong>html</strong> table. and when I process a click on the button, then the id, name, and price item will be changed with the textbox and each textbox has an auto value using the old one, and button 1  will be added one button left button 1, or button 2, or button 3.</p>
  
  <pre><code>function cetakdata()
  {
      if(is_array($_SESSION['pembelian']))
      {
      $total = "";
      echo "Here's your chart" . "&lt;br&gt;";
      $max = count($_SESSION['pembelian']);  
      $th1 = "&lt;th&gt;" . "No" . "&lt;/th&gt;";
      $th2 = "&lt;th&gt;" . "Nama Barang" . "&lt;/th&gt;";
      $th3 = "&lt;th&gt;" . "Harga Barang" . "&lt;/th&gt;";
      $th4 = "&lt;th&gt;" . "Jumlah" . "&lt;/th&gt;";
      $th5 = "&lt;th&gt;" . "Subtotal" . "&lt;/th&gt;";
      $th6 = "&lt;th&gt;" . "Add Edit" . "&lt;/th&gt;";
      echo "&lt;table border=1&gt;";
      echo "&lt;tr&gt;";
      echo $th1 ;
      echo $th2;
      echo $th3;
      echo $th4;
      echo $th5;
      echo $th6;
  
      echo "&lt;/tr&gt;";
      for ($indexo = 0; $indexo &lt; $max; $indexo++) {
     echo "&lt;tr&gt;";
     echo "&lt;td&gt;" . $indexo."&lt;/td&gt;";
     echo "&lt;td&gt;" . $_SESSION['pembelian'][$indexo]['namabarang']."&lt;/td&gt;";
     echo "&lt;td&gt;" . $_SESSION['pembelian'][$indexo]['hargabarang']."&lt;/td&gt;";
     echo "&lt;td&gt;" . $_SESSION['pembelian'][$indexo]['jumlahbarang']."&lt;/td&gt;";
     echo "&lt;td&gt;" . $_SESSION['pembelian'][$indexo]['subtotal']."&lt;/td&gt;";
     echo "&lt;td&gt;" .THIS IS HOW I PUT THE BUTTON ON THE FLY DELETE BUTTON."&lt;/td&gt;";
      $total += $_SESSION['pembelian'][$indexo]['subtotal'];
     echo "&lt;/tr&gt;";
      }
      echo "TOTAL BELANJA = ". $total;
      echo "&lt;/table&gt;";
      }else
      {
          echo "Chart is still Empty";
      }
  }
  </code></pre>
  
  <p>This is the code. When the button created I the other td will be changing into textbox with its value and after user finished edit user can also save it within the save button beside the add button but the save button will be appeared when user click on edit button like the image above :</p>
  
  <p><img src="https://i.stack.imgur.com/h2FFv.png" alt="enter image description here"></p>