Welcome Guest, Not a member yet? Register   Sign In
getResultArray return types
#1

Hi! 
Mysql example select;
Code:
product.ProductID,
product.Title,
product_variation.CostPrice,
ROUND((product_variation.Price * (('. $Vat .' + 100) / 100)), 2) AS Price,

but all result types "string".
i want result types in array;
ProductID -> int
Title ->string
CostPrice -> float
Price -> float
sorry for my bad english.
Reply
#2

It depends on the database driver.
Reply
#3

If you really need the values that way then why not type cast them?

PHP - Type Casting
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(05-22-2022, 07:53 AM)ulas Wrote: Hi! 
Mysql example select;
Code:
product.ProductID,
product.Title,
product_variation.CostPrice,
ROUND((product_variation.Price * (('. $Vat .' + 100) / 100)), 2) AS Price,

but all result types "string".
i want result types in array;
ProductID -> int
Title ->string
CostPrice -> float
Price -> float
sorry for my bad english.

For int, you can use intval()  Read here on w3school
For float, you can use floatval() Read here again
Strings are OK, nothing would be needed.

My advice, for prices go with Decimal on your database, not with float.
Reply
#5

Hi
my database;
[Image: o1lrr7T.png]
[Image: FxCmzXM.png]
but i am generate result all types is string
[Image: CFmDqfg.png]
Reply
#6

See the answer here on Stackoverflow.

When you select data from a MySQL database using PHP the datatype will always be converted to a string. You can convert it back to an integer using the following code:
Code:
$id = (int) $row['userid'];

Or by using the function

PHP Code:
intval(): $id intval($row['userid']); 
Reply
#7

(05-24-2022, 03:03 AM)demyr Wrote: See the answer here on Stackoverflow.

When you select data from a MySQL database using PHP the datatype will always be converted to a string. You can convert it back to an integer using the following code:
Code:
$id = (int) $row['userid'];

Or by using the function

PHP Code:
intval(): $id intval($row['userid']); 

I follow the link on Stack Overflow, and I've gotten some new thoughts. Thank you for providing a better answer to this problem.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB