I was trying to rewrite your code but more and more issues kept cropping up:
- if a property has no image then it will never show up
- at the moment a malicious user could attack your data through your PHP form as you don't check what's in any field before adding the contents of any variable to your SQL - you need to read up on PHP and SQL injection attacks.
- there's no way of knowing which image to use when showing a property, a user could be looking for a $10m beach side property but could just be shown an image of an toilet beside the pool rather than the main picture of the house as there's no way for the program to tell the difference.
I'm going to be honest here and simply point out that it might be better to just hire someone to recreate your table with proper field names, to perhaps have the main image for any property in the listings table which will avoid the join all together, to make your PHP code more robust and then to rewrite your SQL entirely. I don't think this will be a very expensive thing to do (somewhere between 2 and 5 days is my guess) and if you have 30k properties on your portfolio isn't it worth having it all done properly?
but there may be someone on the forum who can do something with your SQL ...