How to get the record total of a table

Asked

Viewed 390 times

2

I need to know how many records there are within my table and add the total find into one variable. I’m doing it this way but it doesn’t work:

   <?php
        $w_querybusca = "SELECT * FROM Elem_matr;";
        $w_queryresultado=f_class_conecta_bd($w_querybusca);

        $result = pg_num_rows($w_queryresultado);
        echo $result;        
    ?>

You should do it in what way?

The problem is: With this example above it only shows the values within the table. What I need is the total contained within this table!

  • I am using Postgresql

  • Can you describe better what doesn’t work? of an error? of a print_r in $w_queryresultado

  • Well, what doesn’t work is that the returned value is 1. And the total of records within the table passes 500.

  • Could you put the code f_class_conecta_bd

  • @lost I do not have access to the bank connection, so I will not be able to show you this.

  • Proxy restriction -.- ! And yes, being small fish in the company is tricky!

  • The print_r returns 1 or an array with a few more keys?

  • The print_r returns 1

  • See if this code changes the return: $w_querybusca = "SELECT COUNT (seq_elem) as total FROM \"Elem_matr\"";&#xA; $w_queryresultado=f_class_conecta_bd($w_querybusca);&#xA;echo $w_queryresultado['total'];

  • This passage that you passed "previously", returns nothing, is blank!

  • Add these two lines at the beginning of the file and see if any errors appear: ini_set('display_errors', true); error_reporting(E_ALL);

  • 1

    I already solved the problem, it was a certain function of the own PostgreSQL.

  • No need to put resolvido in the title, you can mark the reply as accepted with V. why and how to accept an answer

  • It is because if the very person who asked answered. Just to accept in 2 days! There is no mistake with those who visualize this question, I put the solved. But in 2 days I edit!

Show 10 more comments

1 answer

2


The answer to my case was the lack of use of an own command PostgreSQL, that in case it would look like this:

   <?php
        $w_querybusca = "SELECT * FROM Elem_matr;";
        $w_queryresultado=f_class_conecta_bd($w_querybusca);

        $result = pg_num_rows($w_queryresultado);
        echo $result;        
    ?>

Browser other questions tagged

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