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

Link to comment
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

 

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

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.