In general, you need to do a search in the records of the database. There is a select element, the options of which are the names of the table fields and the input element with the search string

<div> <select id="searchBy" class="btn dropdown-toggle" data-toggle="dropdown" style="border: 1px solid #d2d6de;font-size: initial; padding: 0px 10px;"> <option value="">Selectionner une colonne ...</option> <option value="id">id</option> <option value="agence">Réceptif</option> <option value="signature">Nom et Prénom du signataire</option> <option value="email">Mail de contact</option> <option value="website">Site internet</option> <option value="support_user">Nom et prénom - support</option> <option value="support_email">Mail - support</option> <option value="pays">pays</option> <option value="adress1">Adresse 1</option> <option value="adress2">Adresse 2</option> <option value="ville">Ville</option> <option value="zip">Code postal</option> <option value="telephone">Téléphone</option> <option value="fax">Fax</option> </select> </div> <!-- /btn-group --> <input type="text" class="form-control" id="searchKey" style="font-size: initial;" placeholder="" value=""> <span class="input-group-btn"> <button type="button" id="send" class="btn btn-info btn-flat startSearch">Rechercher</button> </span> 

Tell me if I think correctly. At first ajax by request through get method I transfer to the server value of that input and select. In the browser, something is obtained from this http: // test? Name = people & key = vasya ; Then you need, depending on this data, to form a sql query. Here you need your advice on how to form it. So here is the query now

 $result = $pdo->query("SELECT * FROM receptifs ORDER BY $sort $type"); 

Let's say I have meanings

 $name = $_GET['name']; $key = $_GET['key']; 

then we make a request

 $sql = "WHERE $name LIKE ?"; 

And then we substitute it for the previous request.

 $stm = $pdo->prepare("SELECT * SELECT * FROM receptifs $sql ORDER BY $sort $type"); $stm->execute(array($key)); $data = $stm->fetchAll(); 

Is this the right approach? I ask you not to pay attention to the implementation details (direct access to the het, etc.). you just need to know if this way makes sense or is it somehow better to do something else?

  • Do you have any fields in the table? What do you want to choose? - Samuel Loog
  • one
    You do not understand prepare correctly. $a = $pdo->repare("SELECT * FROM table WHERE name = ?"); $a->bindValue(1, $name, PDO::PARAM_STR); $a->execute(); . Your option is not protected from SQL injection. - E_p
  • In the table, the fields are the values ​​of these options. I want to choose records in which the required value is found in the appropriate fields - Kolya Vantukh
  • sphinx to help you - Naumov

0