Jump to content

mysql_fetch_object changing values of a property


mme

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.