andrewgarn Posted June 23, 2008 Share Posted June 23, 2008 I have a login system, which stores the login time into a table as last login. What i want to do is display users who logged in recently, or are using the site currently at the bottom of the page. How would i go about doing this? It might use the last login info it might not, any ideas? EDIT: Also as a further question: Is it possible to put conditional formatting in CSS? I want numbers inside a div to be red if they are negative and green if they are positive Thanks Quote Link to comment Share on other sites More sharing options...
grlayouts Posted June 23, 2008 Share Posted June 23, 2008 something simple would be like take away timenow from time logged in then do a simple if time <300 print user. Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 23, 2008 Share Posted June 23, 2008 Regarding the CSS styling: <?php if ($this==$that) { $class="red"; } elseif ($this==$that2) { $class="orange"; } elseif ($this==$that3) { $class="yellow"; } echo '<span style="font-color:'.$class.';">Hey I\'m a different color font</span>'; ?> Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted June 23, 2008 Author Share Posted June 23, 2008 Regarding the CSS styling: <?php if ($this==$that) { $class="red"; } elseif ($this==$that2) { $class="orange"; } elseif ($this==$that3) { $class="yellow"; } echo '<span style="font-color:'.$class.';">Hey I\'m a different color font</span>'; ?> So youve done it in php instead? I would need if($var < 0) ( $class="red"; ) can i put that span around 50 lines of code or need to be individually declared for each echo? Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 23, 2008 Share Posted June 23, 2008 <?php if ($this==$that) { $class="red"; } elseif ($this==$that2) { $class="orange"; } elseif ($this==$that3) { $class="yellow"; } // assuming you have enabled yourself to parse php within html files: ?> There were <span style="<?=$class?>">AMOUNT</span> users online. Blah blah. <? // do more php stuff, etc. ?> Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted June 23, 2008 Author Share Posted June 23, 2008 something simple would be like take away timenow from time logged in then do a simple if time <300 print user. In the database i have lastlogin stored as Datetime - 2008-06-23 20:17:56 then i retrieve the time using: $date = date("y-m-d H:i:s"); but i minus one from the other i get -2000, why? Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 23, 2008 Share Posted June 23, 2008 <?php $date=strtotime($lastlogin); ?> Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted June 23, 2008 Author Share Posted June 23, 2008 <?php $date=strtotime($lastlogin); ?> gives: 1214241476? Quote Link to comment Share on other sites More sharing options...
plutomed Posted June 23, 2008 Share Posted June 23, 2008 One problem is your date syntax you need a capital Y in stead of a lowercase one. Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted June 23, 2008 Author Share Posted June 23, 2008 One problem is your date syntax you need a capital Y in stead of a lowercase one. That didnt change the results Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 23, 2008 Share Posted June 23, 2008 Yeah... that is right andrew. It should be that number. $now=strtotime(NOW); So, $date>$now etc Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted June 23, 2008 Author Share Posted June 23, 2008 Yeah... that is right andrew. It should be that number. $now=strtotime(NOW); So, $date>$now etc That gives time in seconds? Thanks for your help, again. works now Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 23, 2008 Share Posted June 23, 2008 It's time in seconds from the unix epoch. So you can compare all of your times with that. <?php $date=strtotime($lastupdated); $now=strtotime(NOW); if ($date>$now) { // do this } else { // do that } ?> Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted June 23, 2008 Author Share Posted June 23, 2008 It's time in seconds from the unix epoch. So you can compare all of your times with that. <?php $date=strtotime($lastupdated); $now=strtotime(NOW); if ($date>$now) { // do this } else { // do that } ?> My requirement was just to show users active in last certain amount of time, so this fulfils it perfectly Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted June 23, 2008 Author Share Posted June 23, 2008 <?php if ($this==$that) { $class="red"; } elseif ($this==$that2) { $class="orange"; } elseif ($this==$that3) { $class="yellow"; } // assuming you have enabled yourself to parse php within html files: ?> There were <span style="<?=$class?>">AMOUNT</span> users online. Blah blah. <? // do more php stuff, etc. ?> couldnt make it work you mentioned something about php parsing html, how does it do that? EDIT: nmind made it work using if statements in each class 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.