I have a query like this
select fname,joined_date from employees where id=1
currently the date format I'm using to display this returned employee details is Y-m-d. But now I need to convert the default mysql format Y-m-d to d/m/Y(in all date information display fields).
For me it's very very difficult to go through all the files to do the date format conversion.
So I thought of doing some thing like this in my database class.I have a function like this in my database class
function fetch($res){
$row = mysql_fetch_assoc($res);
foreach($row as $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 this function like this
$row = $db->fetch($res);
or
while($row = $db->fetch($res)){...}
I'm getting the expected output,but with an error message
invalid argument for foreach
it looks like the fetch function code executed (total_num_rows + 1) times
If I use for loop instead of foreach, getting undefined offset error
currently I'm using some thing like this to escape
if(is_array($row)){...}
when i look for the type $res, it showed resource(1st iteration),resource(2nd)
for $row array
array(1st iteration),boolean(2nd)
Can anybody tell me why it's happening? Or is there a better way to do this?
Thanks in advance.