I have a stock status and sometimes when we have "back-orders" the stock value will be -225
I would like to asume this to be zero and display it as so.
Is there a pre-defined function or operatior within that will do so?
I tried intval($stock) but showed the minus figure, any one any ideas?
Is that a negative 225? If so do you want any stock value lower or equal to zero displayed as zero?
harmor wrote:Is that a negative 225? If so do you want any stock value lower or equal to zero displayed as zero?
Yeh, exactly! - If it is Zero or negative the I need itto say 0.
if($stock <= 0) { echo "The stock is 0"; }
What this is does is checks if the value of "$stock" is less than or equal to zero.
Or, if you're doing this in a SQL query, you can do this with a SQL IF() statement:
SELECT IF(`stock` < 0, 0, `stock`) FROM `myTable`
For more information about IF() statements in SQL queries, see this link.