I am trying to run a subquery so that I can sort & ouput results according to which tag column a search term appears in. The query runs fine without the subquery but with it I am getting a 'mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given' error. Any help much appreciated.
$sql = "SELECT * FROM (SELECT trackname, tag1, tag2, tag3, tag4, tag5, songtitle, zip_link, album_id, description, album_name, album_desc,  small_logo  FROM albums, tracks WHERE 
        (tag1 = '{$search_tag}' OR
        tag2 = '{$search_tag}' OR
        tag3 = '{$search_tag}' OR
        tag4 = '{$search_tag}' OR
        tag5 = '{$search_tag}')    AND   tracks.album_id = albums.id ) ORDER BY tag1
        ";  
}  else {
    echo '<br/>please enter a search word or phrase<br/><br/>';
    die;
}
        $result = mysqli_query ($mysqli, $sql);
        if($result === false)  { echo 'mysql error'; }
        $count=mysqli_num_rows($result);
        if ($count < 1) {echo '<span class="sorry">sorry - your search returned no results</div><br/>';}    
            else    {   while ($row = mysqli_fetch_array($result)) 
                `       {   
 
     
     
     
    