SQL / PHP将字符串转换为float或int

I have this sql query..

select i.invoiceid as transactionid, i.date, i.total, 
'invoice' as transaction_type
from invoice

and I ran it in php and echo out the total in a foreach loop like so....

echo gettype($row['total']) . "<br/>";

and all the totals returned string

how would I convert the i.total in my sql query to int or float?

i've tried

convert(int, i.total)

and that didnt work :(

You could try

select i.invoiceid as transactionid, i.date, CAST(i.total as int) as total, 
'invoice' as transaction_type
from invoice

php handles everything (that's not an array/dictionary) as a string unless you specifically tell it not to with something like (int)$row['total'].

http://php.net/manual/en/language.types.string.php#language.types.string.conversion