Welcome Guest, Not a member yet? Register   Sign In
MySQL int fields -> php strings
#3

[eluser]danmontgomery[/eluser]
PHP's mysql_fetch_assoc and mysql_fetch_object functions return only strings, this is clearly explained both on the page you linked to and the pages for these functions on php.net.

I would do something like:

Code:
$query = $this->db->query('some query');
if($query && $query->num_rows()) {
    foreach($query->result_array() as $row) {
        // Replace integer strings with actual integers
        array_walk($row, create_function('&$val','$val = ( is_numeric($val) ? intval($val) : $val );'));

        // Do whatever you need to do
        $data[] = json_encode($row);
    }
}


Messages In This Thread
MySQL int fields -> php strings - by El Forum - 09-16-2010, 11:01 AM
MySQL int fields -> php strings - by El Forum - 09-16-2010, 11:53 AM
MySQL int fields -> php strings - by El Forum - 09-16-2010, 12:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB