Jump to content

can you tell me whats wrong with this?


Glenskie

Recommended Posts

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>";
}

}
?>

Link to comment
Share on other sites

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

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.