I'm trying to build a MySQL query by running through this array and using "if( is_..." conditions to put the appropriate conversion characters in sprintf statements -
Array ( [Fld1] => 2017-09-01 12:15:00 [Fld2] => 111202 [Fld3] => 80988 [Fld4] => 320.15597198865 [Fld5] => 1500 [Fld6] => 0 [Fld7] => 1500 [Fld8] => 1500 [Fld9] => 11 [Fld10] => 3986 [Fld11] => 350 [Fld12] => [Fld13] => [Fld14] => 0 )
The problem is that the is_... functions aren't recognizing the types correctly, e.g. -
String: Fld1 - 2017-09-01 12:15:00 String: Fld2 - 111202 String: Fld3 - 80988 Float: Fld4 - 320.15597198865 Int: Fld5 - 1500 Float: Fld6 - 0 Float: Fld7 - 1500 Float: Fld8 - 1500 String: Fld9 - 11 String: Fld10 - 3986 Int: Fld11 - 350 NULL: Fld12 - NULL: Fld13 - Int: Fld14 - 0
Here's the PHP code -
print_r( $Record ); foreach( $Record as $Field => $Value ) { if( is_int( $Value ) ) echo "Int: $Field - $Value\n"; else if( is_float( $Value ) ) echo "Float: $Field - $Value\n"; else if( is_string( $Value ) ) echo "String: $Field - $Value\n"; else echo "NULL: $Field - $Value\n"; if( is_int( $Value ) ) $Query .= sprintf( "`%s` = %d, ", $Field, $Value ); else if( is_float( $Value ) ) $Query .= sprintf( "`%s` = %.14f, ", $Field, $Value ); else if( is_string( $Value ) ) $Query .= sprintf( "`%s` = '%s', ", $Field, $Value ); }
The first set of if...else...if statements are just temporary to try to see what was happening.
It's making no sense to me because there doesn't appear to be any difference between the integers being identified as strings and those (correctly) identified as integers.
Any ideas anyone?