4
On the whole point of this syntax and proper use of smarty templates.
You should always separate business logic from presentation at all times. Therefore there should not be any calls to the database within a template. Try and move that somewhere and not in the template.
Regarding the syntax, there are many different ways to do the if else statement, if you were to stay true to the pear standard then your example would be correct. However, I prefer a more C style syntax:
$ret = ( $num1<5 ) ? 'Sold Out' : 'Buy Now';
echo $ret;