Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

222
Visualizações
Filtering a postgresql database using a search bar on my website

The Problem

Hello, I am creating a search function that will allow users to search for a specific E-Number and see whether it is derived from animals or not. Firstly, I want to dump all the results on the webpage to see if it is 100% correct. I have successflly connected to the database using PHP on my website but the pg_query is not displaying any results, is there more code I need?

The Code

<?php
        $conn = pg_connect("***** port=*****
            dbname=***** user=***** password=*****");
        $res  = pg_query($conn, "SELECT * FROM enumbers");


        $connection = pg_connect ("host=***** port=*****
            dbname=***** user=***** password=*****");
        if($connection) {
            echo 'connected';
        } else {
            echo 'there has been an error connecting';
        } 
?>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Thanks to @LaurenzAlbe for directing me to an answer, I thought I would show it here:

<?php       
        // Connecting, selecting database
        $dbconn = pg_connect("host=***** port=*****
            dbname=***** user=***** password=*****")
            or die('Could not connect: ' . pg_last_error());    

        // Performing SQL query
        $query = 'SELECT * FROM enumbers';
        $result = pg_query($query) or die('Query failed: ' . pg_last_error());

        // Printing results in HTML
        echo "<table>\n";
        while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
            echo "\t<tr>\n";
            foreach ($line as $col_value) {
                echo "\t\t<td>$col_value</td>\n";
            }
            echo "\t</tr>\n";
        }
        echo "</table>\n";
?>

As you can see by the code above, I completely forgot about actually printng the results in HTML, this is the reason nothing was showing up.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda