Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your case you can simply add <code>WHERE</code> clause with pattern condition and receive desired effect quickly.</p> <pre><code>// basic SQL-injection protection $searchText = htmlspecialchars ($_POST['searchText']); // query with simple search criteria $query = mysql_query("SELECT * FROM persons WHERE FirstName LIKE '%" . $searchText . "%' ORDER by RAND() LIMIT $offset,$per_page"); </code></pre> <p>But this approache have several disadvatages:</p> <ol> <li>Your request is very slow (you will see it with more data in your DB) because you use <code>ORDER BY RAND()</code> construction which sorts randomly <strong>all</strong> entries in DB table and then returns small amount specified in your <code>LIMIT</code> clause; </li> <li>It is neseccary to reload page every time you want to search something. If you want to implement dynamic update of search results list you should use <code>AJAX</code> queries from Javascript.</li> </ol> <p>P.S.: Try not to use deprecated <code>mysql_</code> functions, use <code>PDO</code> or <code>mysqli</code> indstead (they provide built-in SQL-injection protection trough the prepared statments).</p> <p><strong>UPDATE:</strong></p> <p>Ok, you are already using AJAX.</p> <p>So you don't need form at all. Use 2 elements: text input and button.</p> <p>HTML:</p> <pre><code>&lt;input id="q" type='text' name='q' /&gt; &lt;input type="button" onClick="load(1)" value="Refresh"/&gt; </code></pre> <p>Javascript:</p> <pre><code>function load(page){ $("#loader").fadeIn('slow'); var searchText = $('#q').val(); $.ajax({ url: 'index.php?action=ajax&amp;page='+page+'&amp;q='+searchText, success: function(data){ $(".outer_div").html(data).fadeIn('slow'); $("#loader").fadeOut('slow'); } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload