Jump to content

[SOLVED] Quick Question (ha ha)


kev wood

Recommended Posts

if i write an if statement like this

 

if (30 >= $sent_mail && $time_diff < 1) {

// go to this page

} else {

// page the code is held on

}

 

would 30 have to be less than sent mail and time diff greater than 1 for it to display the page the code is held on or would only one of then have to evaluate to true for this to happen.

 

Link to comment
https://forums.phpfreaks.com/topic/108721-solved-quick-question-ha-ha/
Share on other sites

looking at it i dont think it will work for what i need.  i need it to check if sent mail is bigger than the number if it is not continue as normal.  if it is then check if the time since last message sent is greater than 1 minute.  if it is greater than one minute then continue as normal.  if it is not then load a different page.  if you look at an earlier thread by me i have had it set up in different ways but none have worked yet.

 

i have some of it working but i cannot get it to carry on as normal if the time is greater than 1 minute it always lands me on the limit.php page.  my head is hurting now i have been trying to work this out for the last day and a half.

It will work the way you want

 

&& requires both evaluations to return TRUE. It check them from left to right.... if the leftmost evaluation returns FALSE, then anything to the right is disregarded and the if statement fails (thus going to an elseif, else, or continuing with the rest of the script if neither exist). If the leftmost returns TRUE, it will then continue on, making sure other evaluations return TRUE as well

 

|| will work if EITHER evaluation returns TRUE. It check from left to right, but if the leftmost returns FALSE, it will continue trying further evaluations until a TRUE is found. If a true is not found, the statement fails. If any evaluation returns TRUE, the if statement succeeds, and the code within it is executed.

i got the code to work using the following:

 

$query = "SELECT sent_messages FROM email_count"or die(mysql_error());
$results = mysql_query($query);
$arr = mysql_fetch_array($results);
$sent_mail = $arr[0];

$query = "SELECT last_sent FROM time"or die(mysql_error());
$results = mysql_query($query);
$arr = mysql_fetch_array($results);
$sent = $arr[0];

$time_diff = time() - $sent;

$time_diff = intval($time_diff / 60);

if($sent_mail >= 30 && $time_diff < 10) {

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=maillists2.php">'; //redierct user when they can't send any more emails.
} else{
mysql_query("Truncate table time");
mysql_query("Truncate table email_count"); 


// code for the page

 

the code now lets the user go on if sent mail is less than 30 and the time differenc is less then 10 minutes (which will be set to 24 hours when uploaded properly.)  if these evaluate to false then the user is kept on the same page for editing purposes but they cannot send any more messages out for that 24 hour period.

 

thanks for anyone who helped on this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.