Search multiple PHP items database

Asked

Viewed 192 times

0

I have the following problem in PHP, I’m doing a search in a bank Firebird in order to be able to issue a report with the sales requests.

I will enter the order ID one by one and you will return the values. However, each time I do the research it eliminates the existing data, leaving only the last searched value.

<?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);
     echo '<tr>';
     echo '<td>' . $row[0] . '</td>';
     echo '<td>' . $id . '</td>';
     echo '</tr>';
}
?>

Could someone help me ? (in Queries is searching for the customer name only as example, then I will change to the order data, so it is easier to view)

  • I’m not sure but LIKE does not work in INTEGER data type. Try using "SELECT NAME FROM TB_CLIENTE WHERE ID_CLIENTE =". $id

  • So he is searching for the data as I am requesting it normally. I guess I did not formulate the question well. The point is that when I do a new search, it should keep the first and display + the second, but it replaces the data of the first by the second, leaving only one line

  • What are you getting in $_POST['id']? wouldn’t $_GET['id'] ?

  • The question is not clear. What is a new search? Reload this PHP in the browser? If so, clear the screen is the expected behavior.

  • I agree the question was a little confused, I think I’ll close the topic, thanks to those who helped!

1 answer

0

ibase_fecth_row only returns one line at a time. If you want more than one, you can place the call from ibase_fetch_row in a loop loop, to go through all the resultset. It looks like this

//........
$sql = ibase_query("SELECT NOME FROM TB_CLIENTE WHERE ID_CLIENTE LIKE '%".$id."%'");
     while($row = ibase_fetch_row($sql)){
     echo '<tr>';
     echo '<td>' . $row[0] . '</td>';
     echo '<td>' . $id . '</td>';

     echo '</tr>';
}
  • In fact, I will fetch a data at a time, for example, type the id of the first user, it searches and displays, the second, search displays below and so on, understand ?

Browser other questions tagged

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