Real-time table query made by php

0

I have a table created in HTML with PHP and MySQL, and I need that with a input to do a search in real time of that same table, will it be possible?

Here the code:

Body of the page:

<div id="main">
            <div id="header">
                <div id="headerText"><?php 
                if (isset($_GET['equipo'])){
                    echo $_GET['equipo'];
                }elseif (isset($_GET['marca'])){
                    echo $_GET['marca'];
                }
            ?>
                </div>
            </div>
            <div id="content">
                <input type="text" name="consulta" id="consulta" placeholder="Busque por codigo, nombre, presentacion, detalle">
                <div id="resultado"></div>
                <div id="contenido">
                    <table class="table-fill">
                        <thead>
                            <?php if(isset($_GET['equipo'])){
                            ?>
                            <tr>
                                <th>Codigo</th>
                                <th>Descripcion</th>
                                <th>Marca</th>
                                <th>Presentacion</th>
                                <th>Detalle</th>
                                <th>Cantidad</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody class="buscarTabla">
                            <?php

                                while($item = $consulta->fetch_assoc())
                                {
                                ?>
                                    <tr>
                                        <form action="buscar.php" method="post">
                                        <td><input type="hidden" name="codigo" id="codigo" value="<?php echo $item['codRef'];?>"><?php echo $item['codRef'];?></td>
                                        <td><input type="hidden" name="descripcion" id="descripcion" value="<?php echo $item['descripcion'];?>"><?php echo $item['descripcion'];?></td>
                                        <td><input type="hidden" name="marca" id="marca" value="<?php echo $item['marca'];?>"><?php echo $item['marca'];?></td>
                                        <td><input type="hidden" name="present" id="present" value="<?php echo $item['present'];?>"><?php echo $item['present'];?></td>
                                        <td><input type="hidden" name="detalle" id="detalle" value="<?php echo $item['detalle'];?>"><?php echo $item['detalle'];?></td>
                                        <td><input type="text" name="cantidad" id="cantidad" placeholder="0"></td>
                                        <td><button id="btnAgregar">Agregar</button></td>
                                    </form>
                                    </tr>
                        </tbody>
                                <?php 
                                }
                            }elseif (isset($_GET['marca'])) {?>
                        <thead>
                                <tr>
                                <th>Codigo</th>
                                <th>Descripcion</th>
                                <th>Equipo</th>
                                <th>Presentacion</th>
                                <th>Detalle</th>
                                <th>Cantidad</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody class="buscarTabla">
                            <?php

                                while($item = $consulta->fetch_assoc())
                                {
                                ?>
                                    <tr>
                                        <form action="buscar.php" method="post">
                                        <td><input type="hidden" name="codigo" id="codigo" value="<?php echo $item['codRef'];?>"><?php echo $item['codRef'];?></td>
                                        <td><input type="hidden" name="descripcion" id="descripcion" value="<?php echo $item['descripcion'];?>"><?php echo $item['descripcion'];?></td>
                                        <td><input type="hidden" name="equipo" id="equipo" value="<?php echo $item['equipo'];?>"><?php echo $item['equipo'];?></td>
                                        <td><input type="hidden" name="present" id="present" value="<?php echo $item['present'];?>"><?php echo $item['present'];?></td>
                                        <td><input type="hidden" name="detalle" id="detalle" value="<?php echo $item['detalle'];?>"><?php echo $item['detalle'];?></td>
                                        <td><input type="text" name="cantidad" id="cantidad" placeholder="0"></td>
                                        <td><button id="btnAgregar">Agregar</button></td>
                                    </form>
                                    </tr>
                                <?php 
                                }
                            }
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    
asked by Lukas Nada 07.10.2018 в 19:36
source

1 answer

1

If you can do it with JS.

If you start with JS you can recommend jQuery, make an Ajax to the database (if you require the database), or simply check the contents of the tables with filters.

  • Here I'll give you a simple example of how to do the filter without resorting to the BD
  • You might also be interested in other Frameworks such as VueJS or React or Angular
  • Here I'll give you another example, from jQuery vs VueJS for filters.
  • I hope it works for you.

        
    answered by 07.10.2018 в 21:56