Zepo. Posted June 1, 2007 Share Posted June 1, 2007 Im really new at php and i'm wondering what the if function would be to check the date of a comment ($commcreated) , and if the team ($login[id]), has commented in the last 3 hours to the same person ($team[cid]), it wont let them. The table is comments. Sorry for being such a noob at this, but im learning. =] Quote Link to comment https://forums.phpfreaks.com/topic/53914-question-dealing-with-time/ Share on other sites More sharing options...
Barand Posted June 1, 2007 Share Posted June 1, 2007 Something like <?php $sql = "SELECT COUNT(*) FROM comments WHERE NOW() < commcreated + INTERVAL 3 HOUR AND team = '{$login['id']}' AND person = '{$team['cid']}' "; $res = mysql_query($sql); $can_post = (mysql_result($res,0) == 0); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53914-question-dealing-with-time/#findComment-266583 Share on other sites More sharing options...
Zepo. Posted June 1, 2007 Author Share Posted June 1, 2007 Well i need it to where it only allows a comment to be written to the database ever 3 hours. Here's the file: <? include("./config.php"); check_login($login); switch($action){ case "challenge": start_challenge($login); break; default: check_login($login); break; } function check_login($login){ global $config; if(!mysql_num_rows(mysql_query("SELECT id FROM teams WHERE id='$login[id]' AND password='$login[pass]'"))){ $out[body].=" <center> <table width='100%' border='0' cellspacing='1' cellpadding='1' bgcolor='#00000'> <form method='post'> <tr bgcolor='$config[altcolora]'> <td width='100%' valign='center' align='left' colspan='2' background='$config[bg]'> <strong><font face='verdana' color='#c7c7c7'>Comment</strong>"; if($login[failchallenge]){ $out[body].=" <font color='#c7c7c7' size='1'>(Incorrect Login)</font>"; } $out[body].=" </td> </tr> <tr bgcolor='$config[altcolorb]'> <td width='40%' valign='center' align='left'><font face='verdana' size='-2' color='#c7c7c7'>Your ID</td> <td width='60%' valign='center' align='center'><input type='text' name='login[id]' class='button' value='$login[id]' size='25' maxlength='10'></td> </tr> <tr bgcolor='$config[altcolora]'> <td width='40%' valign='center' align='left'><font face='verdana' size='-2' color='#c7c7c7'>Password</td> <td width='60%' valign='center' align='center'><input type='password' name='login[pass]' class='button' value='' size='25' maxlength='10'></td> </tr> <tr bgcolor='$config[altcolorb]'> <td width='40%' valign='center' align='left'><font face='verdana' size='-2' color='#c7c7c7'>Teams ID</td> <td width='60%' valign='center' align='center'><input type='text' name='login[cid]' class='button' value='$login[cid]' size='25' maxlength='10'></td> </tr> <tr bgcolor='$config[altcolora]'> <td width='40%' background='$config[tablex]' valign='center' align='left'><font color='#c7c7c7'>Comment:</td> <td width='60%' background='$config[tablex]' valign='center' align='center'><textarea class='button' name='login[comment]' value='$login[comment]' maxlength='255' style='width:170px; height:160px;'>$login[comment]</textarea></td> </tr> <tr bgcolor='$config[altcolora]'> <td width='100%' valign='top' align='right' colspan='2'> <input type='hidden' name='login[failchallenge]' value='1'> <input type='hidden' name='action' value='challenge'> <input type='submit' name='submit' value='Comment >>'></td> </form> </tr> </table> <br> </center>"; include("$config[html]"); exit; } } function start_challenge($login){ global $config; if($login[id]=="$login[cid]"){ error("You cannot comment yourself."); } $challgdteam=mysql_query("SELECT ladderid,email FROM teams WHERE id='$login[cid]'"); $challgdteam=mysql_fetch_array($challgdteam); if(!$challgdteam[ladderid]){ error("Unable to find the commented team."); } $ladder=mysql_query("SELECT * FROM ladders WHERE id='$challgdteam[ladderid]'"); $ladder=mysql_fetch_array($ladder); if(!$ladder[name]){ error("Unable to load the ladder information."); } $challgr=mysql_query("SELECT * FROM ladder_$ladder[id] WHERE teamid='$login[id]'"); $challgr=mysql_fetch_array($challgr); $challgd=mysql_query("SELECT * FROM ladder_$ladder[id] WHERE teamid='$login[cid]'"); $challgd=mysql_fetch_array($challgd); if(!$challgr[name]){ error("Unable to find your teams stats."); } if(!$challgd[name]){ error("Unable to find the commented teams stats."); } $q = "INSERT INTO `comments` (`commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) VALUES ('$login[id]', '$login[cid]', '$challgr[name]', '$challgd[name]', NOW(), '$login[comment]')"; $rs = mysql_query($q) or die("Error with the query <pre>$q</pre><br>" . mysql_error()); $out[body].=" <br> <center> <b><font color='c7c7c7'> Your comment to $challgd[name] has been recorded!<br> <br></font><font color='yellow'>Please remember, any insulting comments will lead to a strike.</font></b> </center>"; include("$config[html]"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53914-question-dealing-with-time/#findComment-266585 Share on other sites More sharing options...
Zepo. Posted June 2, 2007 Author Share Posted June 2, 2007 Bump, also how do i clean the imput of the comment and get the php and html outta it? Quote Link to comment https://forums.phpfreaks.com/topic/53914-question-dealing-with-time/#findComment-267004 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.