There is such an interesting question, I want to do that would be unloaded from the database (PostgreSQL) to the site and for this information I have already conducted a search.

Here is what I already have (index.php) (added lines that are formed with the base, for example, for now 2):

<!doctype html> <html lang="ru"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="assets/js/main.js"></script> <link rel="stylesheet" href="assets/css/style.css"> <title>Test</title> </head> <body> <table> <thead> <tr> <td><input id="search" type="text" placeholder="search" autofocus> </td> </tr> </thead> <tbody id="task"> <tr class="info-clients" style="display: table-row;"> <td class="id">1</td> <td class="company">Protect</td> <td class="country">Ukraine</td> <td class="good">Beer</td> </tr> <tr class="info-clients" style="display: table-row;"> <td class="id">2</td> <td class="company">Protect</td> <td class="country">Chaina</td> <td class="good">Gear</td> </tr> <script> clients(); </script> </tbody> </table> </body> </html> 

Next, my main.js:

 function clients() { $.ajax({ type: 'GET', url: "../../clients.php", cache: false, success: function (clients) { $('#task').html(clients); } }); } jQuery(document).ready(function () { jQuery('#search').on('change click keyup', function () { var value = jQuery(this).val(); var comp = jQuery('.company').val(); var count = jQuery('.country').val(); var good = jQuery('.good').val(); if ((comp || count || good) != value) { jQuery('.info-clients').css('display', 'none'); } else { jQuery('.info-clients').css('display', 'table-row'); } }) }); 

And here I cant start, the logic here is such that when adding any text to input, it should immediately go through the logic and show only those lines that have these values, but when I’m empty, everything is shown but I just start to enter any word at once everything disappears as if no match was found, help my head for 3 days. I'm breaking what's wrong ((

In order to understand what is in clients.php:

 <?php $conn = mysqli_connect('127.0.0.1','mysql', 'mysql', 'tryself', '3306'); if (!$conn) { exit ('MySQL error'); } $users = mysqli_query($conn, 'SELECT * FROM clients WHERE 1'); while ($row=mysqli_fetch_array($users)) { print "<tr class='info-clients'><td class='id-company'>".$row['id']."</td><td class='email-company'>".$row['email']."</td><td class='company-company'>".$row['company']."</td><td class='country-company'>".$row['country']."</td><td class='good-company'>".$row['good']."</td></tr>"; } ?> 
  • Where is the PHP logic? Maybe the problem is in clients.php - Dmitry

1 answer 1

Tag value is not getting right. It is possible so:

 var count = jQuery('.country').html(); 

the second is how I pon the clients () function; should start when entering characters means it should be moved to

 if ((comp || count || good) != value) { jQuery('.info-clients').css('display', 'none'); } else { jQuery('.info-clients').css('display', 'table-row'); } clients(); 

and the function must also transfer the value to the file "clients.php"

I would change it a bit:

 function clients( value ) { $.ajax({ url: "clients.php", method: "POST", data: { val : value }, success: function (clients) { $('#task').html(clients); } }); } 

well, and would respectively pass the argument in clients (value);

  • I didn’t understand a few things, why change the method from GET to POST, if we just do a sample (in principle, according to the logic that I read, I understand that it’s because of the line that I will ask further). Why do we need this line data: {val: value} and where it still needs to be registered, since I immediately get the error error value is not defined in the logs. Updated info to see the whole picture of the work. - JLomaka
  • A variant with the "POST" method and the "value" transfer was written to transfer the value from the "input" field to the "clients.php" file. I see that you did not transfer anything. Therefore, the "clients ()" function does not need to be changed. - Vladimir Mykytyuk
  • Yes, the point was that I already wanted to do a search on already formed lines in order to remove the possibility of an injection, I know that it is not convenient, since if the list is over 100,500+ positions, then the PPC will lag but the task has yet been given to a small list and a simple form. - JLomaka