Show Postgresql data on web page

Asked

Viewed 36 times

0

I’m new to the subject and ended up stuck in the web.

I would like a help to display/search Postgresql database information and show on a web page.

As I am learning Python, I would like help in this language, but JS would also be interesting to me.

inserir a descrição da imagem aqui

I have a Python file that makes the connection and a SELECT. Python file works right, via terminal. This is a base code that, from this code, I made my own

     cur.execute("SELECT id, name, address, salary  from COMPANY")
    rows = cur.fetchall()
    for row in rows:
       print "ID = ", row[0]
       print "NAME = ", row[1]
       print "ADDRESS = ", row[2]
       print "SALARY = ", row[3], "\n"

    print "Operation done successfully";
cur = conn.cursor()

cur.execute("SELECT id, name, address, salary  from COMPANY")
rows = cur.fetchall()
for row in rows:
   print "ID = ", row[0]
   print "NAME = ", row[1]
   print "ADDRESS = ", row[2]
   print "SALARY = ", row[3], "\n"

print "Operation done successfully";
conn.close()

1 answer

0

Well, using PHP I was able to display the data using js(jquery).

<?php
include_once("./php/conect_postgre.php");

  $consulta_bd = "SELECT * FROM uniao  WHERE regua LIKE 'Co%'";

  $result=pg_query($conexao, $consulta_bd);
  if  (($result)){
      while($linha_usuario = pg_fetch_assoc($result)){
          echo $linha_usuario['regua'] . "<br>";
      }
  }else{
      echo "Nenhum resultado encontrado";
  }

I stored my select in a variable($line_user) or you can call it Row, I passed the "regulate" id of the input to it. Soon after I created a function in jquery to pull this variable, like this:

JQUERY

<script>
$(document).ready(function(){
$.post('paginaquetemoselect.php', function(retorna){
$("conteudo").html(retorna);
});
});
</script>

Where has the "paginaquetemoselect", you put where is your database pulling record, Function(returns) is the function that will receive this record and show in the div called "content", this name ai is the ID of my div where I want to show the records. php is just for you to see how I selected the records. Focus there on jquery.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.