say we leave out the space, and have $dealer_id is 10, and $extra is "order by price asc", the query would become
SELECT * FROM product_table where dealer_id=10order by price asc
^ note that there is no space here
This is not a valid query, since "10order" isn't valid, and "by price asc" is also invalid, so MySQL won't know what to do with this.
With the space added, you will get
SELECT * FROM product_table where dealer_id=10 order by price asc
^ now there is a space!
and all is well with the world
There is no space at the end because you don't need a space at the end (that would just be a trailing space at the end of the query which doesn't mean anything).
As an alternative you could do it like this
$sql = 'SELECT * FROM product_table where dealer_id='.intval($dealer_id) . ' ' . ( isset($extra[$choice])? $extra['choice'] : '' );
// ^ put the space here ... ^ ... instead of here
that way, it will add the space anyway, so either you get the contents of $extra[$choice] after that, or just have a trailing space, which is not a problem in itself, but I find it sloppy