gevans Posted December 16, 2008 Share Posted December 16, 2008 Or with a little change to the database table and query we can sort it relatively easily. If you fancy it add a third field to your table timestamp TIMESTAMP (no length needed) Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716314 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 Ok done and once again i really appretiate your help, Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716317 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 by adding the time stamp im going to need to update the time stamp each time a new message is posted arnt i would that involve changing my input code to update the time stamp also ? Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716318 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 yes, change your query bellow; $query = "INSERT INTO admin_message VALUES ('','$first')"; to... $now = time(); $query = "INSERT INTO admin_message VALUES ('','$first', '$now')"; Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716319 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 Ok, ive changed my Query as instructed posted a nwe alert to make sure it works but the time stamp is displaying as 0000-00-00 00:00:00 is that because of something im doing wrong ? i did add the field correctly timestamp TIMESTAMP thats all i added so im pretty sure its not something im doing EDIT ~ its displaying like this - 0000-00-00 00:00:00 in the database* Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716321 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 sorry my bad, change the field to... timestamp INT Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716322 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 AHHH thats got it now, Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716323 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 ok, so its storing a timestamp similar to 122118493?? Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716324 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 yeah its adding the timestamp now as it should be (1229390101) Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716325 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 change index <?php if($session->logged_in){ echo "<font face='Verdana' color='#FFFFFF' size='2'> Welcome back <b>$session->username</b>, } $username="root"; $password="******"; $database="login"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "SELECT message, timestamp FROM admin_message ORDER BY id DESC LIMIT 1"; $result = mysql_query($query); $detail = mysql_fetch_array($result); $tenMinsAgo = time() - (60*10); if($details['timestamp'] > $tenMinsAgo) { echo '<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000"><tr><td><strong>Message from the administration:</strong>'.$detail['message'].'</td></tr></table><br>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716326 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 Hmmm, thats actually just displaying a blank page now, im not to sure why But its something to do with this piece of code here $tenMinsAgo = time() - (60*10); if($details['timestamp'] > $tenMinsAgo) as i removed that to see if it was that causing the problem and it was :/ Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716329 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 add ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); to the top of your page, just after the <?php tag that should display any errors Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716330 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 yes the error it outputs is Notice: Undefined variable: details in /var/www/html/broadcast.php on line 18 line 18 is if($details['timestamp'] > $tenMinsAgo) i thought it was somethign to do with those two lines but i wasnt sure Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716332 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 Wasn't a hard one to figure out change that line to this... if($detail['timestamp'] > $tenMinsAgo) Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716334 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 Ah sorry i didnt notice it said details rather than detail, thanks a million cant thank you enough, Rick P.S thanks for coping with me on this Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716336 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 no worries. the message should last ten mins!! hit solved Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/page/2/#findComment-716338 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.