[req] profile online

Posted on Tuesday 10th June 2008 at 06:33 PM
Adam981
Adam981's Avatar
Looking to display if a user is online or offline in there profile like we have here at RMB
Posted on Wednesday 11th June 2008 at 11:29 AM
ilyas-shezad
ilyas-shezad's Avatar
Okay this is oging to take some looking at the RMB user system...
1 second Its because i dnot use the member system and the db etc is different to mine.
PHP-MYSQL-JAVASCRIPT-ACTIONSCRIPT-CSS-HTML
Making tutorials for flash, php and javascript
Posted on Wednesday 11th June 2008 at 11:42 AM
ilyas-shezad
ilyas-shezad's Avatar
Okay on your database run this SQL query...

Code
ALTER TABLE `members` ADD `online` VARCHAR( 25 ) NOT NULL AFTER `lastonline` ;


then when in your login.php script when your processing th form and after the $_SESSION have been set put this in...

PHP Code
  1. $timestamp= time();
  2. mysql_query("UPDATE members SET online='$timestamp' WHERE username='$username'");


now on the profile page some where on the page put...
PHP Code
  1. <?php
  2. $varusername="MAke sure you change this appropriately";
  3. $timenow= time();
  4. $query= mysql_query("SELECT * FROM members WHERE online > '$timenow' AND username='$varusername'");
  5. $query_num= mysql_num_rows($query);
  6.  
  7. if ($query_num == "0"){
  8. $online="No";
  9. }else{
  10. $online="Yes";
  11. }
  12. ?>


Well that should work... phew i shoulda made it a tutorial...
Oh well, anyway tell e if the code works for you i just made it right now lol but im pretty sure it'll work if you do it right.
PHP-MYSQL-JAVASCRIPT-ACTIONSCRIPT-CSS-HTML
Making tutorials for flash, php and javascript
Posted on Wednesday 11th June 2008 at 11:47 AM
ilyas-shezad
ilyas-shezad's Avatar
forgot to mention that you will need to add
PHP Code
  1. <?
  2. $timestamp= time();
  3. mysql_query("UPDATE members SET online='$timestamp' WHERE username='$username'");
  4. ?>

to config.php so that the suers online status is always updated and not just when he logs in.
PHP-MYSQL-JAVASCRIPT-ACTIONSCRIPT-CSS-HTML
Making tutorials for flash, php and javascript
Posted on Wednesday 11th June 2008 at 12:58 PM
ilyas-shezad
ilyas-shezad's Avatar
p.s. this one is just a test...
(image removed as dead)
PHP-MYSQL-JAVASCRIPT-ACTIONSCRIPT-CSS-HTML
Making tutorials for flash, php and javascript
Posted on Wednesday 11th June 2008 at 03:38 PM
Adam981
Adam981's Avatar
Erm when im loged in it displays "no"
Posted on Wednesday 11th June 2008 at 03:42 PM
ilyas-shezad
ilyas-shezad's Avatar
try changing...
PHP Code
  1. <?php
  2. $varusername="MAke sure you change this appropriately";
  3. $timenow= time();
  4. $query= mysql_query("SELECT * FROM members WHERE online > '$timenow' AND username='$varusername'");
  5. $query_num= mysql_num_rows($query);
  6.  
  7. if ($query_num == "0"){
  8. $online="No";
  9. }else{
  10. $online="Yes";
  11. }
  12. ?>

to
PHP Code
  1. <?php
  2. $varusername="MAke sure you change this appropriately";
  3. $timenow= time()-3600;
  4. $query= mysql_query("SELECT * FROM members WHERE online > '$timenow' AND username='$varusername'");
  5. $query_num= mysql_num_rows($query);
  6.  
  7. if ($query_num == "0"){
  8. $online="No";
  9. }else{
  10. $online="Yes";
  11. }
  12. ?>
PHP-MYSQL-JAVASCRIPT-ACTIONSCRIPT-CSS-HTML
Making tutorials for flash, php and javascript
Posted on Wednesday 11th June 2008 at 03:43 PM
Adam981
Adam981's Avatar
I'm thinking maybe im doing the $varusername= wrong?
Posted on Wednesday 11th June 2008 at 03:45 PM
Adam981
Adam981's Avatar
Now it keeps saying im online when im not
Posted on Wednesday 11th June 2008 at 03:52 PM
Adam981
Adam981's Avatar
maybe the tutorial display users online is messing it up? because i use that also
Login or register to respond to this forum topic.