Q: mysql_query not fulfilling all specified parameters so here is my code and I will tell you the problem after that:
<script language='javascript' type='text/javascript'>
    setInterval( function() {
    $('#responsechat<?php echo $otherchatuser ?>').load('echogetconversation.php?username=<?php echo $username; ?>&otherchatuser=<?php echo $otherchatuser; ?>&numberofmessages=<?php echo $numberofmessages; ?>');
    <?php
    $subtractlogintime8 = time() - 600;
    $data8 = mysql_query("SELECT * FROM loggedin WHERE username='$otherchatuser' and time > '$subtractlogintime'");
    $numrows8 = mysql_num_rows($data8);
    ?>
    if (<?php echo $numrows8; ?> == 1 )
    {
    document.getElementById("checkloggedin<?php echo $otherchatuser; ?>").innerHTML = '<img src="loggedin.png">';
    document.getElementById("checkloggedin<?php echo $otherchatuser; ?>").style.marginLeft = '5px';
    }
    else
    {
    document.getElementById("checkloggedin<?php echo $otherchatuser; ?>").innerHTML = '';
    }
    }, 4000);
    </script>

This is my code, which gets users who are logged in and also does other things.  The problem that I am having occurs on this line:
 $data8 = mysql_query("SELECT * FROM loggedin WHERE username='$otherchatuser' and time > '$subtractlogintime'");

The query successfully gets users from the database, but seems to be ignoring the "and time > '$subtractlogintime'");" part of the query.  I have no idea why this is occurring and anyone who could possibly tell me what I have forgotten would be extremely appreciated.  Thanks.

A: TIME is a reserved keyword in MySQL because of the TIME datatype. If it's not crashing, you would probably better off backticking your "TIME" keyword to refer to the field time.
$data8 = mysql_query("SELECT * FROM loggedin WHERE username='$otherchatuser' and `time` > '$subtractlogintime'");

Also note that, this code COULD be prone to SQL injection but we can't be sure without seeing the full code...
