View data in PHP table

Asked

Viewed 534 times

1

I am making a sales report and need to organize the data coming from a bank in Firebird make a report on PHP, however I am not getting know how many data are coming from the bank. Because the function ibase_num_fields does not return how many are the data. And then how would the organization of this data in table ?

   $host='localhost:C:/bd_relatorio/clipp.FDB';    

   $dbh=ibase_connect($host,'SYSDBA','masterkey');

   $stmt = 'SELECT NOME FROM TB_CLIENTE';

   $sth = ibase_query($dbh, $stmt);   

   $total = ibase_num_fields($sth);

   if($total > 2){

     while ($row = ibase_fetch_row($sth)) {
         echo $row[0], "\n";
     }
   }
   echo $total;
   ibase_free_result($sth);
   ibase_close($dbh);
?>

2 answers

2


There is no function in the library ibase_ returning the number of lines in a query.

There are two options:

  • the first via SQL is to execute the same query with a count().

  • The second way is to create a variable that stores the number of rows, something like:

--

$totalLinhas = 0;
if($sth){
   while ($row = ibase_fetch_row($sth)) {
      echo $row[0], "\n";
      $totalLinhas++;
   }
   echo "total: ". $totalLinhas;
}
  • Thank you very much! It worked. Now I need to organize the data that comes in table. If possible could help me ? Because I am unable to display php information inside html, even using the <php tag? ?>

  • @Progmen, the first line is fixed because it’s the header, inside the while put something like <tr><td>valor1</td><td>valor2</td></tr> for each returned column goes a pair <td></td>

  • Correct. I will try to create here, the problem was to make this data appear in html msm. But anything I create another question, already helped me properly. Thank you

0

// count of received lines in the array $total = ibase_num_rows($sth);

// loops the array, assembling the table rows. // Just print the variable

while($row = ibase_fetch_object($sth))
{
  $linhas = '<tr><td>Clientes: '. $row->NOME .'</td></tr>';
}
  • 1

    Diego, base does not have that function, had already tried. Thank you.

  • 1

    Right, I’m not familiar with Ibase, but in any case, you can in sql do a Count(NAME) as total, for example before. To get this return.

  • 1

    Yes, perfectly. And I was a little mistaken, I managed to do without the need to count the lines. haha vlw

Browser other questions tagged

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