widgets – Global $ wpdb does not show the correct data with the function call

I have a code that shows the last 3 pages updated recently or post.

This code works perfectly when I add it to the theme file sidebar.php.

get_results ("SELECT ID, post_title FROM $ wpdb-
> posts WHERE post_status = & publish; AND (post_type = & # 39; OR) post_type =
& # 39; post & # 39;) AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC 
 LIMIT $count")):
 ?>