How can i echo the results in the same page as the search form is (wordpress)?(i`m newbie)

   <form action="" id="searchform" method="POST">
<input name="searchquery" type="text" placeholder="Nume, spital" size="30" maxlength="40">
        <select name="filter">
            <option value="ALL">Toate judetele</option>
            <option value="AB">Alba</option>    
        </select>
    <input type="submit" value="Cauta">
     </form>

the php code

 global $wpdb;
$con=mysqli_connect("localhost","root","");
$search = mysql_real_escape_string(trim($_POST['searchquery']));
if($_POST['filter'] == "ALL"){
$sqlCommand = $wpdb->get_results("SELECT * FROM `wp_doctors` WHERE `name` LIKE '%searchquery%'");
} else if($_POST['filter'] == "AB"){ $sqlCommand = $wpdb->get_results("SELECT * FROM `wp_doctors` WHERE `name` LIKE '%searchquery%' AND `city`= 'Alba'   ");
} //more if`s, i just cuted for example
foreach ( $sqlCommand as $result) 
{
    echo $result->id;
    echo $result->name;
    echo $result->spec;
}

and if i`m using at the form action atribute it will take me to the index page.
Thanks!

Read more here: Results on the same page as the search form php


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: