Jump to content

Reloading data from mysql


Kaboom

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/221831-reloading-data-from-mysql/
Share on other sites

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

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.

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.