Problem when creating html table from MYSQL with PHP

0

I am creating a table with data extracted from my MySql database with php but when I want to start showing the data it marks me errors like:

  

Warning: mysqli_query (): Empty query in   C: \ xampp \ htdocs \ Safety \ table.php on line 29

     

Warning: mysqli_fetch_row () expects parameter 1 to be mysqli_result,   boolean given in C: \ xampp \ htdocs \ Safety \ table.php on line 30

I have already reviewed PHP manuals and forums but I can not make it work, I have little time with PHP I hope you can help me, this is my code:

<?php
include('conexion.php');
$con = mysqli_connect("localhost","root","")or die("Problemas al conectar");
mysqli_select_db($con,"safety") or die("Problemas con la Base Datos");


//Se crea una tabla para mostrar los resultados


?>
<div class="row">
    <div class="col-sm-12">
        <h2>Tabla Reporte</h2>
        <table class="table table-hover table-condensed table-bordered">
            <caption>
            <button class="btn btn-primary">Agregar
                <span class="glyphicon glyphicon-plus"></span>
            </button>
            </caption>
            <tr>
                <td>NOMINA</td>
                <td>NOMBRE</td>
                <td>COMENTARIO</td>
            </tr>
            <?php

                $sql = mysqli_query($con, "SELECT nomina,nombre,comentario FROM empleado,comentarios");
                $resultado=mysqli_query($con,$sql);
                while($ver=mysqli_fetch_row($resultado)){

            ?>
            <tr>
                <td><?php   echo $ver[1]    ?></td>
                <td></td>
                <td></td>
            </tr>
            <?php
                }
                //Cerrar la conexión
                mysqli_close($con);
            ?>
        </table>
    </div>
</div>
    
asked by Xavi 23.10.2018 в 18:58
source

2 answers

0

Hello it is necessary that you publish your code to be able to directly solve your errors, in any way, I give you a small example of what you are trying to do, it's just a matter of adapting it to your need.

Greetings.

<?php
//parametros de la base de datos
$usuario='root';
$password='root';
$servidor='localhost';
$bd_name = 'nombre_bd';

// Realiza conexion
 $conexion = mysqli_connect($servidor, $usuario, $password) or die('No se pudo conectar: ' . mysqli_error());
mysqli_select_db($conexion, $bd_name) or die('No se pudo seleccionar la base de datos'. mysqli_error());

echo('entra a conexion');

// Realizar una consulta MySQL
$consulta = 'SELECT * FROM users';
$resultado = mysqli_query($connection, $consulta) or die('Consulta fallida: ' . mysqli_error());

// Imprimir los resultados en HTML
echo "<table borde='2'>";
echo "<tr>";
echo "<th>Usuario</th>";
echo "</tr>";

while ($columna = mysqli_fetch_array( $resultado))
{
 echo "<tr>";
 echo "<td>" . $columna['username'] . "</td>";
 echo "</tr>";
}
echo "</table>";
?>
    
answered by 23.10.2018 в 19:16
0

The problem I see is in the following line:

$sql = mysqli_query($con, "SELECT nomina,nombre,comentario FROM empleado,comentarios");

You are doing a FROM to two tables. You must make a SELECT statement for each table; or, a JOIN to these two tables. This should be the employee query:

$sql = mysqli_query($con, "SELECT nomina,nombre,comentario FROM empleado");

I do not know if the comment field belongs to an employee, but that would be it.

    
answered by 24.10.2018 в 16:29