I want 1 line o/p for 2 search conditions. One line o/p for search w/o company name is working fine but search with specific name is not working

<?php

    include 'config.php';

    if(!empty($_GET['companyname']) && !empty($_GET['designation']))
    {
        $name = !empty($_GET['companyname']) ? strtolower(trim($_GET['companyname'])) : '';
        $designation = !empty($_GET['designation']) ? strtolower(trim($_GET['designation'])) : '';
        $conditions = " LOWER(companyname) ='$name'";
        if(!empty($name)) {
            $conditions .= " AND LOWER(companyname) ='$name' ";
        }

        $sqlSalary = "SELECT companyname,designation  max(annualctc) as MaxSalary, min(annualctc) as MinSalary , AVG(annualctc) as avgSalary FROM `salery_calculator` WHERE $conditions group by companyname";
        $resultSalary = mysqli_query($conn, $sqlSalary);
        $row_count = mysqli_num_rows( $resultSalary );
        if($row_count > 0){
            $html = "<table class='table table-bordered'><thead><tr><th>Company Name</th><th>Designation</th><th> Max Salary</th><th>Middle Salary</th><th>Min Salary</th></tr></thead><tbody>";
            while ($p_row = mysqli_fetch_array($resultSalary)) {
                $html .= "<tr><td>" . ucwords($name) . "</td><td> " . ucwords($designation) . "</td><td> " . $p_row['MaxSalary'] . "</td><td>" . round($p_row['avgSalary']) . "</td><td>" . $p_row['MinSalary'] . "</td></tr>";
            }
            $html .="</tbody></table>";
            $errorcode = 200;
        } else{
            $html = "<p>No record found on search criteria</p>";
            $errorcode = 105;
        }
    }

    else{
        $html = "<p>Required field missing</p>";
        $errorcode = 105;
    }
    if(empty($_GET['companyname']) && !empty($_GET['designation'])){

        $designation = !empty($_GET['designation']) ? strtolower(trim($_GET['designation'])) : '';
        $conditions = " LOWER(designation) ='$designation'";
        if(empty($name) && !empty($designation)) {
            $conditions .= " AND LOWER(designation) ='$designation' ";
        }

        $sqlSalary = "SELECT designation, max(annualctc) as MaxSalary, min(annualctc) as MinSalary , AVG(annualctc) as avgSalary FROM `salery_calculator` WHERE $conditions group by designation and companyname";
        $resultSalary = mysqli_query($conn, $sqlSalary);
        $row_count = mysqli_num_rows( $resultSalary );
        if($row_count > 0){
            $html = "<table class='table table-bordered'><thead><tr><th>Designation</th><th> Max Salary</th><th>Average Salary</th><th>Min Salary</th></tr></thead><tbody>";
            while ($p_row = mysqli_fetch_array($resultSalary)) {
                $html .= "<tr><td> " . ucwords($designation) . "</td><td> " . $p_row['MaxSalary'] . "</td><td>" . round($p_row['avgSalary']) . "</td><td>" . $p_row['MinSalary'] . "</td></tr>";
        }    $html .="</tbody></table>";
            $errorcode = 200;
        } 
        else{
            $html = "<p>No record found on search criteria</p>";
            $errorcode = 105;
        }
    }

    else
    {
        $html = "<p>Required field missing</p>";
        $errorcode = 105;
    }






    echo json_encode(array('error_code'=>$errorcode, 'message'=>$html));
?>