Paul-D Posted yesterday at 01:46 PM Share Posted yesterday at 01:46 PM (edited) Hi. I have a drop down box that should show years 2024 and 2025. I can not get the next year to be included if today is greater than 19th November. Can any help with this please. This is on lines 134 - 139. The current date $DD $MM and $YYYY are automaticaly set anyway on lines 31 to 33. And the years are established on lines 53 to 55. <?php // Banking Version 2.0.0 01-12-2023 Desmond O'Toole. error_reporting(E_ALL); ini_set('display_errors', '1'); include_once ("secure/SecureFunctionsBankPDO.php"); include_once ("../secure/SecurePDO.php"); date_default_timezone_set('Europe/London'); session_start(); Session_Init(); $page = "Libray Selection"; if(!isset($_SESSION["Pk"])) { header('Location: index.php'); exit; } $Pk = $_SESSION["Pk"]; if(KeyCheckX($Pk)== 0) { header('Location: index.php'); exit; } $EndTime = KeyTestX($Pk, 0); //SILLY this returns 1 or -1 $_SESSION["current_page"] = $page; $Comment_Name = time(); $Comment_Name = dechex(time()); $_SESSION['COMMENT_NAME'] = $Comment_Name; $DD = date('d'); // Default to current date $MM = date('m'); $YYYY = date('Y'); $qBalance = GetBalance(); $Date = $qBalance['EntryDate']; $Value = $qBalance['BalanceValue']; $stamp = strtotime($Date); $_SESSION["DD_Balance"] = date('d' ,$stamp); $_SESSION["MM_Balance"] = date('m' ,$stamp); $_SESSION["YYYY_Balance"] = date('Y' ,$stamp); $_SESSION['C_Forward'] = $Value; $SE_MyReason = $_SESSION['DE_MyReason']; if($_SESSION["DE_DD_Entry"] == "") { $_SESSION["DE_DD_Entry"] = $DD; $_SESSION["DE_MM_Entry"] = $MM; $_SESSION["DE_YYYY_Entry"] = $YYYY; } $ThisYear = date("Y",time()); $NextYear = $ThisYear + 1; $PreviouseYear = $ThisYear - 1; if (!isset($_SESSION['DE_Money_In'])) $_SESSION['DE_Money_In'] = '0.00'; if (!isset($_SESSION['DE_Money_Out'])) $_SESSION['DE_Money_Out'] = '0.00'; if (!isset($_SESSION['DE_Comment'])) $_SESSION['DE_Comment'] = ""; $SE_Money_In = $_SESSION['DE_Money_In']; $SE_Money_Out = $_SESSION['DE_Money_Out']; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Bank Home 2</title> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <META http-equiv="imagetoolbar" CONTENT="no"> <link rel="stylesheet" href="stylesheets/Library.css" type="text/css"> <link rel="stylesheet" href="stylesheets/LibraryMenu.css" type="text/css"> </head> <body> <div id="PageTitle"> <img src="images/LibraryBanner.jpg" alt=""> </div> <?php include('SideMenu.php'); ?> <div id="PageContent"> <form action="DataInputUpdate.php" method="post"> <h3>User: <?=greeting() . " Ends on " . $EndTime ?></h3> <div style="width:650px;height:60px;padding:10px;overflow:hidden;"> <div style="width:440px;float:left;"> Date: Carried forward: £<span style="color:red;"><?=$_SESSION['Error_3'] ?></span> <input type="text" maxlength="10" size="5" name="BF" style="text-align:right" value="<?=$_SESSION['C_Forward'] ?>" > <select name="DD_Balance" style="width:40px"> <?php for($days=1;$days<32;$days++) { ?> <option value="<?=$days ?>" <?php if ($_SESSION["DD_Balance"] == $days){ ?> SELECTED <?php } ?>><?=$days ?></option> <?php } ?> </select> <select name="MM_Balance" style="width:60px"> <option value="1" <?php if ($_SESSION["MM_Balance"] == "1"){ ?> SELECTED <?php } ?>>Jan</option> <option value="2" <?php if ($_SESSION["MM_Balance"] == "2"){ ?> SELECTED <?php } ?>>Feb</option> <option value="3" <?php if ($_SESSION["MM_Balance"] == "3"){ ?> SELECTED <?php } ?>>Mar</option> <option value="4" <?php if ($_SESSION["MM_Balance"] == "4"){ ?> SELECTED <?php } ?>>Apr</option> <option value="5" <?php if ($_SESSION["MM_Balance"] == "5"){ ?> SELECTED <?php } ?>>May</option> <option value="6" <?php if ($_SESSION["MM_Balance"] == "6"){ ?> SELECTED <?php } ?>>Jun</option> <option value="7" <?php if ($_SESSION["MM_Balance"] == "7"){ ?> SELECTED <?php } ?>>July</option> <option value="8" <?php if ($_SESSION["MM_Balance"] == "8"){ ?> SELECTED <?php } ?>>Aug</option> <option value="9" <?php if ($_SESSION["MM_Balance"] == "9"){ ?> SELECTED <?php } ?>>Sep</option> <option value="10" <?php if ($_SESSION["MM_Balance"] == "10"){ ?> SELECTED <?php } ?>>Oct</option> <option value="11" <?php if ($_SESSION["MM_Balance"] == "11"){ ?> SELECTED <?php } ?>>Nov</option> <option value="12" <?php if ($_SESSION["MM_Balance"] == "12"){ ?> SELECTED <?php } ?>>Dec</option> </select> <select name="YYYY_Balance" style="width:60px"> <?php if($MM == 1) { ?> <option value="<?=$PreviouseYear ?>" <?php if($_SESSION["YYYY_Balance"] == $PreviouseYear){ ?> SELECTED <?php } ?> ><?=$PreviouseYear ?></option> <?php } ?> <option value="<?=$ThisYear ?>" <?php if($_SESSION["YYYY_Balance"] == $ThisYear){ ?> SELECTED <?php } ?> ><?=$ThisYear ?></option <?php if($MM == 12 || $MM == 11 && $DD > 19) { ?> <option value="<?=$NextYear ?>" <?php if($_SESSION["YYYY_Balance"] == $NextYear){ ?> SELECTED <?php } ?> ><?=$NextYear ?></option> <?php } ?> </select> </div> <br><br> <div style="float:left;clear:both;"><input class="MyButton"type="submit" name="direction" value="Prev Balance"></div> </div> <div style="width:650px;height:10px;padding:10px;overflow: hidden;"> <select name="DD_Entry" style="width:40px"> <?php for($days=1;$days<32;$days++) { ?> <option value="<?=$days ?>" <?php if ($_SESSION["DE_DD_Entry"] == $days){ ?> SELECTED <?php }?>><?=$days ?></option> <?php } ?> </select> <select name="MM_Entry" style="width:60px"> <option value="1" <?php if ($_SESSION["DE_MM_Entry"] == "1"){ ?> SELECTED <?php } ?>>Jan</option> <option value="2" <?php if ($_SESSION["DE_MM_Entry"] == "2"){ ?> SELECTED <?php } ?>>Feb</option> <option value="3" <?php if ($_SESSION["DE_MM_Entry"] == "3"){ ?> SELECTED <?php } ?>>Mar</option> <option value="4" <?php if ($_SESSION["DE_MM_Entry"] == "4"){ ?> SELECTED <?php } ?>>Apr</option> <option value="5" <?php if ($_SESSION["DE_MM_Entry"] == "5"){ ?> SELECTED <?php } ?>>May</option> <option value="6" <?php if ($_SESSION["DE_MM_Entry"] == "6"){ ?> SELECTED <?php } ?>>Jun</option> <option value="7" <?php if ($_SESSION["DE_MM_Entry"] == "7"){ ?> SELECTED <?php } ?>>July</option> <option value="8" <?php if ($_SESSION["DE_MM_Entry"] == "8"){ ?> SELECTED <?php } ?>>Aug</option> <option value="9" <?php if ($_SESSION["DE_MM_Entry"] == "9"){ ?> SELECTED <?php } ?>>Sep</option> <option value="10" <?php if ($_SESSION["DE_MM_Entry"] == "10"){ ?> SELECTED <?php } ?>>Oct</option> <option value="11" <?php if ($_SESSION["DE_MM_Entry"] == "11"){ ?> SELECTED <?php } ?>>Nov</option> <option value="12" <?php if ($_SESSION["DE_MM_Entry"] == "12"){ ?> SELECTED <?php } ?>>Dec</option> </select> <select name="YYYY_Entry" style="width:60px"> <?php if($MM == '1' && $DD < 7) { ?> <option value="<?=$PreviouseYear ?>" <?php if ($_SESSION["DE_YYYY_Entry"] == $PreviouseYear){ ?> SELECTED <?php } ?> ><?=$PreviouseYear ?></option> <?php } ?> <option value="<?=$ThisYear ?>" <?php if ($_SESSION["DE_YYYY_Entry"] == $ThisYear){ ?> SELECTED <?php } ?> ><?=$ThisYear ?></option> <?php if($MM > '10') { ?> <option value="<?=$NextYear ?>" <?php if ($_SESSION["YYYY_Balance"] == $NextYear){ ?> SELECTED <?php } ?> ><?=$NextYear ?></option> <?php } ?> </select> <span style="color:red;"><?=$_SESSION['Error_5'] ?></span> </div> <div style="width:650px;height:60px;padding:10px;overflow: hidden;"> Money in: £ <input style="text-align:right;" type="text" maxlength="10" size="4" name="MoneyIn" value="<?=$SE_Money_In ?>" size="8"> <!-- <span style="color:red;"><?=$_SESSION['Error_6'] ?></span> --> <br><br> Money Out: £ <input style="text-align:right;" type="text" maxlength="10" size="4" name="MoneyOut" value="<?=$SE_Money_Out ?>" size="8"> <!-- <span style="color:red;"><?=$_SESSION['Error_7'] ?></span> --> </div> <div style="width:650px;height:70px;padding:10px;overflow:hidden;"> Reason: <?php $qReason = GetReason(); ?> <select name="Reason"> <?php while($row = $qReason->fetch()) { ?> <option value="<?=$row['ReasonID'] ?>" <?php if($SE_MyReason == $row['ReasonID']) { ?> selected <?php } ?> ><?=$row['Reason'] ?></option> <?php } ?> </select> <span style="color:red;"><?=$_SESSION['Error_8'] ?><br><br></span> Comment <input type="text" maxlength="32" size="42" name= "<?=$Comment_Name ?>"; value=""> Max 32 Characters </div> <div style="width:650px;height:40px;padding:10px;overflow:hidden;"> Hi-light <input type="checkbox" maxlength="1" size="1" name="Bold"> </div> <div style="width:460px;height:90px;padding:10px;overflow:hidden;"> <input class="MyButton"type="submit" name="direction" value="Add record"><br><br><br> <input class="MyButton"type="submit" name="direction" value="Statement"> </div> </div> </form> </body> </html> Edited yesterday at 02:10 PM by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/325589-help-with-conditional-statement/ Share on other sites More sharing options...
mac_gyver Posted yesterday at 03:08 PM Share Posted yesterday at 03:08 PM The closing </option> tag on the $ThisYear output is missing the closing >, so the following markup is broken. check the 'view source' of the output in your browser. 1 Quote Link to comment https://forums.phpfreaks.com/topic/325589-help-with-conditional-statement/#findComment-1641061 Share on other sites More sharing options...
Paul-D Posted yesterday at 03:36 PM Author Share Posted yesterday at 03:36 PM Thanks for that. Can't think how that was not copied down to the next line. Quote Link to comment https://forums.phpfreaks.com/topic/325589-help-with-conditional-statement/#findComment-1641062 Share on other sites More sharing options...
Phi11W Posted 12 hours ago Share Posted 12 hours ago 18 hours ago, Paul-D said: Thanks for that. Can't think how that was not copied down to the next line. I might suggest that it could be because you are jumping between HTML and PHP with appalling rapidity. I prefer to write PHP code that builds or outputs strings that just happen to contain HTML. echo '<select name="YYYY_Entry" style="width:60px">'; if($MM == '1' && $DD < 7) printf( '<option value="%1$s"%2$s>%1$s</option>' , $PreviouseYear , ( ( $_SESSION["DE_YYYY_Entry"] == $PreviouseYear ) ? ' selected="selected"' : '' ) ); printf( '<option value="%1$s"%2$s>%1$s</option>' , $ThisYear , ( ( $_SESSION["DE_YYYY_Entry"] == $ThisYear ) ? ' selected="selected"' : '' ) ); if($MM > '10') printf( '<option value="%1$s"%2$s>%1$s</option>' , $NextYear , ( ( $_SESSION["DE_YYYY_Entry"] == $NextYear ) ? ' selected="selected"' : '' ) ); echo( '</select> ' ); Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/325589-help-with-conditional-statement/#findComment-1641082 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.