Kaboom Posted December 16, 2010 Share Posted December 16, 2010 I have a session to check when the users login and fetch the details from their account but when they edit their avatar I want it to update the value right away. For it to change the value for the user they need to log out and back in, destroying the original session and recreating a new one on that account. Is there a way to have it always getting the data I need from the database while they're logged in? Because I don't want it to only get the orignial data in case they change a setting so they don't have to log out and then back in to change the setting. I hope you understand Quote Link to comment https://forums.phpfreaks.com/topic/221831-reloading-data-from-mysql/ Share on other sites More sharing options...
denno020 Posted December 16, 2010 Share Posted December 16, 2010 I have never tried this before or anything, but I thought it might be a good idea: When they save their new settings, you could have a php script run that will update the database with the new values, and then query the database, getting all user's data again, and re-assigning the session variables to these new query results.. One of those variables would be the avatar, which, I imagine, would update when the session variable is updated with the new information.. I could be way off though, but it's just an idea I thought could work. Denno Quote Link to comment https://forums.phpfreaks.com/topic/221831-reloading-data-from-mysql/#findComment-1147983 Share on other sites More sharing options...
Kaboom Posted December 16, 2010 Author Share Posted December 16, 2010 I have never tried this before or anything, but I thought it might be a good idea: When they save their new settings, you could have a php script run that will update the database with the new values, and then query the database, getting all user's data again, and re-assigning the session variables to these new query results.. One of those variables would be the avatar, which, I imagine, would update when the session variable is updated with the new information.. I could be way off though, but it's just an idea I thought could work. Denno In the saving of the avatar it does currently update the SQL database with the info Now the problem there is that the data while being updates is only loading the data from the beginning of the session. Somehow I need the profile or accounts to always be updating/fetching the new data from the database. Quote Link to comment https://forums.phpfreaks.com/topic/221831-reloading-data-from-mysql/#findComment-1148153 Share on other sites More sharing options...
Kaboom Posted December 16, 2010 Author Share Posted December 16, 2010 Double: Okay so I made an update function, will this work? function update($updateid) { global $db_id; $query="SELECT count(*) FROM users WHERE ID=$updateid"; $result=mysql_query($query, $db_id); $row=mysql_fetch_row($result); return $row; } Then for the profile I have it calling like echo update($avatar); Will this work to fetch the row and return the right answers right away? Quote Link to comment https://forums.phpfreaks.com/topic/221831-reloading-data-from-mysql/#findComment-1148164 Share on other sites More sharing options...
denno020 Posted December 17, 2010 Share Posted December 17, 2010 Why are you counting the results? Just say: SELECT 'avatar field' FROM users WHERE id=$updateid (update avatar session variable) (replace 'avatar field' with the column name for the avatar). I would imagine that'd work alright... Quote Link to comment https://forums.phpfreaks.com/topic/221831-reloading-data-from-mysql/#findComment-1148505 Share on other sites More sharing options...
laffin Posted December 23, 2010 Share Posted December 23, 2010 I really dont see the need to re-read the db to update the session variable. when u can do it in your processing script. $avatar=isset($_POST['avatar'])?trim($_POST['avatar']):NULL if(!empty($avatar) && $avatar!=$_SESSION['avatar']) { $update[]='avatar=\''. mysql_real_escape_string($avatar). '\''; $_SESSION['avatar']=$avatar; } . . . if(!empty($update)) { $sql='UPDATE users SET '. implode(',',$update) ." WHERE id=$userid"; mysql_query($sql); } however this is just a simple example Quote Link to comment https://forums.phpfreaks.com/topic/221831-reloading-data-from-mysql/#findComment-1150904 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.