Jump to content

Tabela dinâmica PHP com Select2


António Rosmaninho

Recommended Posts

Boa tarde a todos,

Sou muito verdinho em programação, estou a tentar construir uma tabela dinâmica em PHP, e a utilizar um select2 (javascript)

A ideia da tabela é através do select2 (carregar lista de artigos de uma tabela sql e selecionar um artigo), depois introduzir a quantidade e poder adicionar quantos linhas forem necessárias, para depois enviar para tabela de SQL...

Fazer uma linha com os campos que preciso já consegui, mas não consigo fazer de forma como se fosse uma tabela dinâmica.

Já encontrei alguns exemplos para criar tabelas dinâmicas, mas onde o utilizador insere de forma manual todos os campos, neste caso, quero consultar uma lista existente para poder dar entrada de um artigo para stock.

alguém me dá umas dicas?

<?php
require "verifica.php";
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);
session_start();
require('header.php');
?>

<div id="mainContent">
  <h1 class="style12" align="center">:: ENTRADA DE FARDAMENTO</h1></td></tr></table>
  <?php
  // Ligação às  BDD para receber os users e artigos

  $conn= new mysqli('localhost','root','xxxxx','bdd');

$sql_forn= "SELECT * from fornecedores" ;
  $result_forn=mysqli_query($conn, $sql_forn);

  $sql_artigos= "SELECT * from artigos";
  $result_art=mysqli_query($conn, $sql_artigos);
   ?>
  <html>
  <head>
    <!-- configuração do Select2 -->

    <title> </title>
  <link rel= "stylesheet" type="text/css" href="css/select2.min.css" style="width: 100%">
  <script
  			  src="https://code.jquery.com/jquery-3.5.1.js"
  			  integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
  			  crossorigin="anonymous"></script>

  <script src="css/select2.min.js"></script>

 <table  border="0" width="1200px">

<!-- Inicia formulário de Entrada -->

   <form class="form-inline" action="../pages/registamovi.php">
      <tr>
      <td valign="left" >
      <p style="color:#666666">Data :<span style="color: red;"> *</span></p>
      
      <td colspan="3">
      <input type="text" placeholder="" name="Data" required size="11"  >

      <td valign="left" >
      <p style="color:#666666">Fatura :<span style="color: red;"> </span></p>
      </td>
      <td colspan="3">
      <input type="text" placeholder="" name="fatura" size="10"  >
      </td>



      <td valign="top" >
      <p style="color:#666666">Fornecedor:<span style="color: red;"> </span></p>
      </td>
      <td colspan="3">
      <section style="text-halign:left " name="fornecedor">
        <select id="pesquisa_art" style= "width:200px;">
          <option value "selecionar" > selecionar
          <?php  while ($ver=mysqli_fetch_row($result_forn))
           {?> <option value="<?php echo $ver[0] ?>">
             <?php echo $ver[0] ?>
              </option>
          <?php } ?>
        </select>

      </section>
      </body>
    </html>

    <script type="text/javascript">
      $(document).ready(function(){
                    $('#pesquisa_art').select2();

                                });
    </script>


    <script type="text/javascript">
    $(document).ready(function(){
      $('#pesquisa').select2();

    });
    </script>


  </td>
      </td>
      <tr>
      <td>
      <tr>
      </tr>
      </head>
  <td>

<!-- FINALIZA O SELECT2 DA SELECÇÃO FORNECEDOR ***************    -->

  <!-- Retorna os dados dos Artigos com texto pesquisa -->
    <body>


    <section style="text-halign:justify;">
      <select id="pesquisa" style= "width:300px;">
        <?php
         while ($ver1=mysqli_fetch_row($result_art))
         {?> <option value="<?php echo $ver1[0] ?>">
           <?php echo $ver1[1] ?>
            </option>
        <?php } ?>

      </select>
    </section>
  </html>


<td valign="top" >
<p style="color:#666666">Quantidade :<span style="color: red;"> </span></p>
</td>
<td colspan="3">
<input type="text" placeholder="" name="qt" size="5"  >
</td>
<tr>

Obrigado

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.