PDA

View Full Version : PHP help - Using Date?



Johno
03-08-2008, 08:58 PM
Hey,

I know the title is a little vague but anywho!

Im currently making an alert script, when the alert is submitted to the MySQL DB it logs the time it is sent in a field called "time"

Now I am trying to make it so the alert only shows for a period of lets say a second for a user alert and then a minute for a sitewide alert?

How do I get it to only display if it is within this time? Also how could I make it so only two alerts could be sent per hour?

Im not exactly the best at explaining what I mean lol :P


<?PHP

/*
* @copyright 2008
*/

include_once 'includes/php/config.php'; // Includes the User System Config
include_once 'includes/php/radio_dj.php'; // Includes the Radio Config File (To get current DJ)

echo '<span class="SUBHEADLINE">Send an Alert!<br />
</span><em>Alert a specific user! (Only the current DJ can send)</em><br /><br />'; // Header Echo :)

switch ($_GET[sent]) { // Specifies how the switch class works - In this case ?sent=
default: // Obvious, Sets the default page

if ($logged[user] == $servertitle || $logged[level] == 11) { // Checks if you are DJing or Admin
echo '<font color="#009900"><strong>You are the current DJ - Alert a user below:</font></strong>
<br><br>';

echo '<form method="post" action="?page=useralert&sent=yes">
<table border="0" cellpadding="2" cellspacing="2">
<tr>
<td>Username:</td>
<td><input name="username" type="text" id="username" size="20" maxlength="20"/></td>
</tr>
<tr>
<td>Alert: </td>
<td><input name="message" type="text" id="message" size="70" maxlength="100"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="right">
<input type="submit" name="send" id="send" value="Send Alert">
</div></td>
</tr>
</table>
</form>';

}
else {
echo '<strong><font color="red">You are not the current DJ - This can only be used by the online DJ!</strong></font>';
}

break; // Break the page!

case 'yes':

if ($_POST[send]) {
if($_POST['username'] == ""|$_POST['message'] == ""){
echo "<strong><font color='red'>You have missed out something, <a href='?page=useralert'>Go back</a> and try again!</font></strong>";
}else{
if($_POST['username'] == "ALL"){


$message = $_POST[message];
$sentfrom = $logged[username];
$sendto = $_POST[username];
$senttime = date('H:s');
$sentdate = date('d/m/y');
$query = "INSERT INTO alert (name, message, sentfrom, ipsent, time, date) VALUES('$sendto','$message','$sentfrom','ALL', '$senttime','$sentdate')";
mysql_query($query) or die(mysql_error());
echo "<font color='#009900'><strong>Your alert has been sent to everyone!</strong></font><br>The alert was: <strong>$message</strong>";
}else{

$ipsendto = mysql_query("SELECT * FROM users");
$ipsend = mysql_fetch_assoc($ipsendto);
$message = $_POST[message];
$sentfrom = $logged[username];
$sendto = $_POST[username];
$senttime = date('H:s');
$sentdate = date('d/m/y');
$query = "INSERT INTO alert (name, message, sentfrom, ipsent, time, date) VALUES('$sendto','$message','$sentfrom','$ipsend[last_ip]', '$senttime','$sentdate')";
mysql_query($query) or die(mysql_error());
echo "<font color='#009900'><strong>Your alert has been sent to $sendto!</strong></font><br>The alert was: <strong>$message</strong>";
}
}

}
// Do this next :)

break;
}
?>I know its not the best code in the world lol, this is the code to submit it to the database, not view the alert

Calon
03-08-2008, 09:24 PM
php.net/time?

Johno
03-08-2008, 09:49 PM
Found another way to do it, Reason I wanted this was so it was like a log - Just going to log separately now.

Thanks anyway!

Want to hide these adverts? Register an account for free!