Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
issue with printing a table in php/mysqli

So basically my code isnt working here. The confusing part is that at a bare minimum it should be printing the table header, which it is not doing.

here is my function

public function getUsers(){
    global $connectstr_dbhost, $connectstr_dbname, $connectstr_dbpassword, $connectstr_dbusername;
    $link=mysqli_connect($connectstr_dbhost, $connectstr_dbusername, $connectstr_dbpassword,$connectstr_dbname);
    $sql = "SELECT * FROM `users`";
    $result = mysqli_query($link, $sql);



    echo ("
         <table border='1'>
         <tr>
         <th>ID</th>
         <th>First Name</th>
         <th>Last Name</th>
         <th>Username</th>
         <th>Email</th>
         </tr>

    ");

    while($row = mysqli_fetch_array($result))
    {
        echo(
            "<tr>" .
            "<td>" . $row['id']. "</td>".
            "<td>" . $row['fname'] . "</td>".
            "<td>" . $row['lname'] . "</td>".
            "<td>" . $row['username'] . "</td>".
            "<td>" . $row['email'] . "</td>".
            "</tr>"

        );
    }


    echo "</table>";
}

Pretty new to php and I feel as if the answer is really simple, any assistance would be appreciated.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Maybe is that `user` over user. Try and see if resolve. If not try this code:

[TRY Save the content of the function in another file and just make an echo to see if the function is called]

public function getUsers(){
    global $connectstr_dbhost, $connectstr_dbname, $connectstr_dbpassword, $connectstr_dbusername;
    $link = mysqli_connect($connectstr_dbhost, $connectstr_dbusername, $connectstr_dbpassword,$connectstr_dbname) or die('Não foi possível conectar');
    $sql = "SELECT * FROM users";
    $result = $link->query($sql);

    echo "
         <table border='1'>
         <tr>
         <th>ID</th>
         <th>First Name</th>
         <th>Last Name</th>
         <th>Username</th>
         <th>Email</th>
         </tr>

    ";

    while($row = $result->fetch_assoc()) {
        echo "<tr>" .
                "<td>" . $row['id']. "</td>".
                "<td>" . $row['fname'] . "</td>".
                "<td>" . $row['lname'] . "</td>".
                "<td>" . $row['username'] . "</td>".
                "<td>" . $row['email'] . "</td>".
            "</tr>";
    }

    echo "</table>";
}
over 4 years ago · Santiago Trujillo Denunciar

0

Figured it out, the problem was I had not imported the database class.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda