mme Posted July 19, 2012 Share Posted July 19, 2012 Hi, I have the following code $rs = mysql_query('SELECT * FROM transactions WHERE acid='.$acc); $result = array(); while($row = mysql_fetch_object($rs)) { array_push($result, $row); } echo json_encode($result); Now I wish to change the value of a certain column in each row that is returned from the database. The column is called 'date' and contains a unix timestamo that I wish to format using my function stime($var,1). How would I do this? Kind Regards, mme Quote Link to comment https://forums.phpfreaks.com/topic/265928-mysql_fetch_object-changing-values-of-a-property/ Share on other sites More sharing options...
xyph Posted July 19, 2012 Share Posted July 19, 2012 Like... this? while($row = mysql_fetch_object($rs)) { $row->date = stime($row->date, 1); array_push($result, $row); } Quote Link to comment https://forums.phpfreaks.com/topic/265928-mysql_fetch_object-changing-values-of-a-property/#findComment-1362621 Share on other sites More sharing options...
Pikachu2000 Posted July 19, 2012 Share Posted July 19, 2012 What does stime() do? Can it be done with MySQL functions instead? Quote Link to comment https://forums.phpfreaks.com/topic/265928-mysql_fetch_object-changing-values-of-a-property/#findComment-1362622 Share on other sites More sharing options...
mme Posted July 19, 2012 Author Share Posted July 19, 2012 Like... this? while($row = mysql_fetch_object($rs)) { $row->date = stime($row->date, 1); array_push($result, $row); } Thanks its all working! I tried $row['date'] before but I did not know it was possible to do it like you said ($row->date). What does stime() do? Can it be done with MySQL functions instead? It formats the date as well as checks it against a generated hash. But thank you for your suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/265928-mysql_fetch_object-changing-values-of-a-property/#findComment-1362624 Share on other sites More sharing options...
xyph Posted July 19, 2012 Share Posted July 19, 2012 Like... this? while($row = mysql_fetch_object($rs)) { $row->date = stime($row->date, 1); array_push($result, $row); } Thanks its all working! I tried $row['date'] before but I did not know it was possible to do it like you said ($row->date). What does stime() do? Can it be done with MySQL functions instead? It formats the date as well as checks it against a generated hash. But thank you for your suggestion. Like... this? while($row = mysql_fetch_object($rs)) { $row->date = stime($row->date, 1); array_push($result, $row); } Thanks its all working! I tried $row['date'] before but I did not know it was possible to do it like you said ($row->date). What does stime() do? Can it be done with MySQL functions instead? It formats the date as well as checks it against a generated hash. But thank you for your suggestion. Well, you used mysql_fetch_object rather than mysql_fetch_assoc Quote Link to comment https://forums.phpfreaks.com/topic/265928-mysql_fetch_object-changing-values-of-a-property/#findComment-1362625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.