i`m kinda new in this domain and i got stucked in here. I need to extract data from DB and echo it on the screen into one wordpress page. I dont know what i have made wrong in the following code. Please help me, i want to learn as fast as i can this kind of problems.

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<ul id="mysearchul >"
<li><span class="sch">Caută medicul in functie de judet</span>
<input type="text" name="searchquery" value="Nume, Spital"/>
 <select name="search">
     <option value="ALL">Toate judetele</option>
     <option value="AB">Alba</option>
             <option value="AG">Arges</option>
           </select></li>
     <li><input type="submit" id="searchsubmit" value="Cauta" /></li>
     </ul>  
     </form>
    global $wpdb;
$search_output="";
    if(isset($_POST['searchquery']) && $_POST['searchquery'] != ""){
$searchquery = preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['searchquery']);
if($_POST['search'] == 'ALL') {
    $sqlCommand = $wpdb->get_results("SELECT * FROM wp_doctors WHERE name LIKE '%searchquery%' OR spec LIKE '%searchquery%' ORDER BY name ");
    }else if($_POST['search'] == "AB"){
        $sqlCommand = $wpdb->get_results("SELECT * FROM wp_doctors WHERE (name LIKE '%searchquery%' OR spec LIKE '%searchquery%') AND city='Alba' ORDER BY ID ");
        }else if($_POST['search'] == "AG"){
        $sqlCommand = $wpdb->get_results("SELECT * FROM wp_doctors WHERE ( name LIKE '%searchquery%' OR spec LIKE '%searchquery%') AND city='Arges'  ORDER BY ID "); 
        }
$count=mysql_num_rows($query);
if($count > 1){
    $search_output .= "<hr /> $count results for <strong>$searchquery</strong><hr />$sqlCommand<hr />";
    while($row=mysql_fetch_array($query)){
        $id = $row["$id"];
        $name=$row["name"];
        $spec=$row["spec"];
        $instit=$row["instit"];
        $search_output .= "Item $id --Nume: $name -- Specializare: $spec -- Institutie: $instit <br />";
        }//end of while
    }else {
         $search_output .= "<hr /> 0 results for <strong>$searchquery</strong><hr />$sqlCommand<hr />";
    }//end of if
 echo $search_output;

Read more here: Search form in php problems


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: