ibolui Posted May 26, 2008 Share Posted May 26, 2008 hi, i am facing a weird problem with my first attempt at flex, php and mysql. please pardon me if this is not the correct place to post my question. i had a form created using flex and json, with php as the backend. below are segments of my codes.. //get the raw JSON data and cast to String var rawData:String = String(event.result); var user = JSON.decode(rawData); first_name.text = user.first_name; last_name.text = user.last_name; email.text = user.email; if (user.gender == "male") { male.selected = true; } else { female.selected = true; } var bday:Date = new Date(user.birthday); day.selectedIndex = bday.getDate() - 1; month.selectedIndex = bday.getMonth(); year.selectedIndex = year_array.indexOf(bday.getFullYear().toString()); ........ echo json_encode($_SESSION['user']); when i first load the page, everything is being populated correctly on the flex frontend. however, when i refresh the page using f5, the birthday fields are incorrect. in the sense that it becomes 1 jan 1970. i tried to print out the value of user.birthday and it is indeed 1 jan 1970. but i am not sure why it has become this value.. Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 26, 2008 Share Posted May 26, 2008 it your date function sorry lookup date and mkdate php Quote Link to comment Share on other sites More sharing options...
.josh Posted May 26, 2008 Share Posted May 26, 2008 If it initially shows the correct date, then it's probably not a sql problem. Might possibly be php's fault but we'd have to see some php code, particularly the code that uh..interfaces with json/flex or whatever (not really that keen on those..don't really know how that works..), possibly even the php code that gets the info from the db. Quote Link to comment Share on other sites More sharing options...
ibolui Posted May 26, 2008 Author Share Posted May 26, 2008 hmmm.. i think i found where the problem lies.. $user_temp = $_SESSION['user']; $user_temp->birthday = date("n/j/Y", $user_temp->birthday); echo json_encode($user_temp); in my code i tried to create a temp var to store $_SESSION['user'], and then edit the birthday inside. however i think the $_SESSION['user']->birthday has also been edit. how do i actually prevent this Quote Link to comment Share on other sites More sharing options...
.josh Posted May 26, 2008 Share Posted May 26, 2008 You know, I really suck at oop but if $_SESSION['user'] is an object, I think you need to do $user_temp = new $_SESSION['user']; but again...I am the suck at oop so that's just a crap shoot and I hope someone better can help you. Quote Link to comment Share on other sites More sharing options...
.josh Posted May 26, 2008 Share Posted May 26, 2008 yeah..no. I was wrong. However, I was poking around, and it seems that if $_SESSION['user'] is an object, and you do $user_temp = $_SESSION['user']; $user_temp now becomes a copy of the whatever class $_SESSION['user'] is, but it does not carry the information (I think that's why it's showing the wrong date, or rather, a default of the first date it can show). I think you are gonna have to just forget about using $user_temp and just use your session variable, or, if I'm reading this thing correctly, you might be able to do $user_temp =& $_SESSION['user']; Quote Link to comment Share on other sites More sharing options...
ibolui Posted May 26, 2008 Author Share Posted May 26, 2008 emm.. i not really sure but i did tried using =& but the outcome is not what i wanted. basically i used $user_temp = $_SESSION['user'] because i want to change some fields of the user, but i do not want to change the instance inside session. hence i thought i could create a new variable with a copy of the user instance in session. but upon changing the $user_temp, the user instance inside session is also changed as well... Quote Link to comment Share on other sites More sharing options...
.josh Posted May 26, 2008 Share Posted May 26, 2008 Man I don't know then...if you wanted to create a copy without changing the original, then according to the manual, you had it right (without the &)...so...I'm not sure why it would change the other one...but like I said, I'm a complete newb when it comes to oop. Sorry I couldn't be of help Quote Link to comment Share on other sites More sharing options...
ibolui Posted May 26, 2008 Author Share Posted May 26, 2008 i did some testing and realise that if i do this, $aaa = 123; $bbb = $aaa; $bbb = 456; $aaa will remains as 123. but if i did this, class c { var $x; } $aaa = new c(); $aaa->x = 123; $bbb = $aaa; $bbb->x = 456; $aaa->x will become 456. but i do not want $aaa->x to change.. i am quite new to this also. someone enlighten me how to do it? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 26, 2008 Share Posted May 26, 2008 sounds like you might want to do some cloning: http://us3.php.net/language.oop5.cloning i'm totally new to it, but found that info. Quote Link to comment Share on other sites More sharing options...
ibolui Posted May 26, 2008 Author Share Posted May 26, 2008 yeah it works! just as simple as $clone = clone $obj; thanks! Quote Link to comment Share on other sites More sharing options...
.josh Posted May 26, 2008 Share Posted May 26, 2008 well darn, I came across clone when I was researching but it didn't seem like that's what you were going for. Glad you got it sorted out! Quote Link to comment 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.