Before you do something with the $x, and after the query, add this:

PHP Code: 
if(mysql_num_rows($x)){
  
//Do your stuff
}else{
  
//No results found