1

私はこのSQLクエリを持っています..

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

そして、私はそれをphpで実行し、foreachループで合計をエコーアウトしました....

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

すべての合計が返されましたstring

SQL クエリの i.total を int または float に変換するにはどうすればよいですか?

私はもう試した

convert(int, i.total)

そしてそれはうまくいきませんでした:(

4

2 に答える 2

3

php のようなもので特に指定しない限り、すべて (配列/辞書ではない) を文字列として処理します(int)$row['total']

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

于 2012-05-02T19:41:51.160 に答える
1

あなたは試すことができます

select i.invoiceid as transactionid, i.date, CAST(i.total as int) as total, 
'invoice' as transaction_type
from invoice
于 2012-05-02T19:40:00.177 に答える