View data in Array

Asked

Viewed 283 times

0

I’m doing a query in a database and I need to display the information on the screen, but searching one at a time. I tried to do by array, but it is not displaying the vector.

Code:

<?php
$a = $_GET['a'];
if($a == "buscar"){
  $id = $_POST['id'];
  $sql = ibase_query("SELECT NOME FROM TB_CLIENTE WHERE ID_CLIENTE LIKE '%".$id."%'");
  $row = ibase_fetch_row($sql);
  $vetorDados = array();
  $i=0;
  $vetorDados[$i]= ibase_fetch_row($sql);
  echo '<tr>';
  echo '<td>' . $vetorDados[$i] . '</td>';
  echo '<td>' . $i . '</td>';
  echo '</tr>';
  $i++;
}
?>

1 answer

3


You have yet to create one while to display data, another detail that became redundant was you create an array $vetorDados to print the bank result, with the variable $row is already a array, below follows the code to display the database data.

<?php
$a = $_GET['a'];
if($a == "buscar"){
$id = $_POST['id'];
$sql = ibase_query("SELECT NOME FROM TB_CLIENTE WHERE ID_CLIENTE LIKE '%".$id."%'");
$i = 1;
while($row = ibase_fetch_row($sql)){
   echo "<tr>";
   echo "<td>{$row['NOME']}</td>";
   echo "<td>{$i}</td>"; 
   echo "</tr>";
   $i++;
   }    
}
?>

The key to the variable $row is the name of the column of the bank to which you want to print the information.

  • @Progmen I had forgotten to close to tag </tr>

  • So, earlier I was doing so, but then he searches "all" the names with aqele id, and if I look for another he erases the previous, I wanted him to be making a list as he would add

  • See if I understand, you want to create a list as if it were a history of the last searched records?

  • This, as I give more ids they will appear in order on the screen, the way I am doing, each value q I enter it erases the previous. if($a == "buscar"){&#xA; $id = $_POST['id'];&#xA; $sql = ibase_query("SELECT NOME FROM TB_CLIENTE WHERE ID_CLIENTE = $id ");&#xA; $row = ibase_fetch_row($sql);&#xA; echo '<tr>';&#xA; echo '<td>' . $row[0] . '</td>';&#xA; echo '</tr>';&#xA; }

  • @Progmen understood, but this way is not possible using php for it to work that way you need to use jquery or javascript creating a dynamic list in the innerHTML this way you must complete this question and create a new one, requesting assistance when creating a dynamic list ordered with search data.

  • Perfectly, thank you! Did not know haha, thought q php would do it. thank you.

  • I’ll ask the question, can you help me through there ?

Show 3 more comments

Browser other questions tagged

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