Glenskie Posted September 27, 2011 Share Posted September 27, 2011 can you tell me whats wrong with this? <?php $age= 60; if( isset($_SESSION['logedin']) ) { $q = mysql_query('SELECT id=`$id`, DATE_FORMAT(`last_activity`,"%a, %b %e %T") as `last_activity`,UNIX_TIMESTAMP(`last_activity`) as `last_activity_stamp`FROM `mymembers`WHERE `$logOptions_id` <> "'.($_SESSION['logedin']).'"'); $isonlinecheck = mysql_query($q); if ($isonlinecheck ="last_activity_stamp + $age "< time()){ $isonline = "is <font color='green'>online!</font>";} else { $isonline = "is<font color='red'> offline!</font>"; } } ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted September 27, 2011 Share Posted September 27, 2011 What's wrong with... your post? Sure. You posted a chunk of code with a very vague question (the same one in your post as you used for the thread title, even). No background information. No explanation of the code. No description of the problem. Quote Link to comment Share on other sites More sharing options...
sunfighter Posted September 27, 2011 Share Posted September 27, 2011 And this: $q = mysql_query('SELECT id=`$id`, ....... $isonlinecheck = mysql_query($q); Makes no sense. Quote Link to comment Share on other sites More sharing options...
Glenskie Posted September 27, 2011 Author Share Posted September 27, 2011 ok sorry , its check the database for the time and where the id is placed , it keeps showing online no matter what Quote Link to comment Share on other sites More sharing options...
jcbones Posted September 27, 2011 Share Posted September 27, 2011 Not really sure how the logic behind this works, but I understand the problems with this script. Why yes, I would be glad to break it down for you. <?php $age= 60; //set a variable called age, assign an integer of 60 to it. if( isset($_SESSION['logedin']) ) { //if a session index called logedin is set, it could be empty though (most likely is, because the session has NOT been started). $q = mysql_query('SELECT id=`$id`, DATE_FORMAT(`last_activity`,"%a, %b %e %T") as `last_activity`,UNIX_TIMESTAMP(`last_activity`) as `last_activity_stamp`FROM `mymembers`WHERE `$logOptions_id` <> "'.($_SESSION['logedin']).'"'); //run a mysql_query (I don't see a database connection here), then store the Resource in a variable call q. $isonlinecheck = mysql_query($q); //attempt to assign a Resource of a Resource to another variable called isonlinecheck (it won't work). if ($isonlinecheck ="last_activity_stamp + $age "< time()){ //run an if statement which reads: set a string of 'last_activity_stamp + 60' to a variable called isonlinecheck, then see if that string is less than the current timestamp. $isonline = "is <font color='green'>online!</font>";} //set a string to a variable called isonline. else { $isonline = "is<font color='red'> offline!</font>"; } } ?> So, there is a few problems here. 1. You must start a session (if auto session start is not enabled on the server), at the top of the script. 2. You must connect to a database. 3. You are calling the query and storing the result resource, then calling another query on that. I assume that was a mistake, (hey it happens). 4. In the if statement you use a single =, which is an assignment operator, comparison operators is == and ===. 5. Also in the if statement I think you wanted to add age to the last_activity_stamp, but you did it in string syntax which will NOT work. So, I will take my suggestions and incorporate them into the script. Crossing my fingers and hoping that I get it right on the first time around (I doubt it, I'm all jacked up on 5 hour energy ATM). WHOOOOHOOOOOOO. <?php session_start(); /*Please add your database connection details below*/ include('database_connection_file.php'); /*database connection should have already been made*/ $age= 60; //set a variable called age, assign an integer of 60 to it. if( isset($_SESSION['logedin']) ) { //if a session index called logedin is set, it could be empty though (most likely is, because the session has NOT been started). $q = 'SELECT id, DATE_FORMAT(`last_activity`,"%a, %b %e %T") as `last_activity`,UNIX_TIMESTAMP(`last_activity`) as `last_activity_stamp`FROM `mymembers`WHERE `$logOptions_id` <> \''.($_SESSION['logedin']).'\''; $isonlinecheck = mysql_query($q); //Assign a Resource to a variable called isonlinecheck (it won't work). $row = mysql_fetch_assoc($isonlinecheck); //get the row of data from the Resource. if (($row['last_activity_stamp'] + $age)< time()){ //run an if statement $isonline = "is <font color='green'>online!</font>";} //set a string to a variable called isonline. else { $isonline = "is<font color='red'> offline!</font>"; } } ?> I think that is it... if it doesn't work, post back and I'll probably still be up trying to work out all this 5 hour energy. AHHHHHHHHHHHH.... Quote Link to comment Share on other sites More sharing options...
Glenskie Posted September 27, 2011 Author Share Posted September 27, 2011 hey i have to go to be but i will put the rest of the script up ... thank you for trying 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.