1

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 :(

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

You could try

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

1 Comment

This gives me an SQL Error(1064)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.