php - Changing date format in mysql_fetch returned array -


i have query this

select fname,joined_date employees id=1 

currently date format i'm using display returned employee details y-m-d. need convert default mysql format y-m-d d/m/y(in date information display fields).

for me it's very difficult go through files date format conversion.

so thought of doing thing in database class.i have function in database class

function fetch($res){    $row = mysql_fetch_assoc($res);    foreach($row $key=>$value){    if(preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/',$value))       $row[$key] = date('d/m/y',strtotime($value));    }    return $row; }//end function 

and i'm using function this

$row = $db->fetch($res); 

or

while($row = $db->fetch($res)){...} 

i'm getting expected output,but error message

invalid argument foreach

it looks fetch function code executed (total_num_rows + 1) times

if use loop instead of foreach, getting undefined offset error

currently i'm using thing escape

if(is_array($row)){...} 

when type $res, showed resource(1st iteration),resource(2nd)

for $row array

array(1st iteration),boolean(2nd)

can tell me why it's happening? or there better way this?

thanks in advance.

when reach end of results, mysql_fetch_assoc() returns false. need check case:

function fetch($res){    $row = mysql_fetch_assoc($res);    if ($row) {      foreach($row $key=>$value){        if(preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/',$value)){           $row[$key] = date('d/m/y',strtotime($value));        }      }    }    return $row; } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -