486974 Posted May 25, 2009 Share Posted May 25, 2009 Hi All, I am trying to give separate dates a value e.g January 01 = 100, January 02 = 120, January 03 = 90 so when someone types lets say January 01 into my form and then 3 into days part of the form the script will add January 01, January 02 and January 03 together and echo 310 i want to do it for a whole year the simple form i am using is <form action="welcome.php" method="post"> Start Date: <input type="text" name="sdate" /> End Date: <input type="text" name="days" /> <input type="submit" /> </form> then on the welcome.php i have <?php echo $_POST['sdate']; ?> X <?php echo $_POST['days']; ?> Days = (TOTAL) UK Sterling which produces the date and days but I'm baffled to how i put values and then add them together can anyone help please Link to comment https://forums.phpfreaks.com/topic/159627-values-to-dates/ Share on other sites More sharing options...
GingerRobot Posted May 25, 2009 Share Posted May 25, 2009 Well how are you assigning the values to each day? Without some sort of logical pairing, your only choice is a big (alright, 365 rows aint big, but i'd still rather not hand type it) table of days and their corresponding 'value'. Link to comment https://forums.phpfreaks.com/topic/159627-values-to-dates/#findComment-841926 Share on other sites More sharing options...
486974 Posted May 25, 2009 Author Share Posted May 25, 2009 <?php $txt="January 01"; $x=100; $txt="January 02"; $x=120; $txt="January 03"; $x=90; ?> then i used an if statement and nothing worked i am new to this and trying to teach myself with the online tutorials but its just mind boggling Link to comment https://forums.phpfreaks.com/topic/159627-values-to-dates/#findComment-841931 Share on other sites More sharing options...
Ken2k7 Posted May 25, 2009 Share Posted May 25, 2009 Try an array, but it'll be a very long one - okay 365 (possibly 366) - entries. <?php $array = array( 'January 01' => 100, 'January 02' => 120, . . . ); Then to get the number, you would just use $array['January 01'], which will output 100. Link to comment https://forums.phpfreaks.com/topic/159627-values-to-dates/#findComment-841967 Share on other sites More sharing options...
486974 Posted May 25, 2009 Author Share Posted May 25, 2009 How do i call the array after someone else has inputted there date and once they type in the amount of days add the values of the dates together and then print on screen. Dont know if i have explained that right the form is at http://www.disneysvacationvillarentals.net/3_Bedroom/BL1099/welcome.php If you type in January 01 and then 3 you will see what i mean Link to comment https://forums.phpfreaks.com/topic/159627-values-to-dates/#findComment-841977 Share on other sites More sharing options...
Ken2k7 Posted May 26, 2009 Share Posted May 26, 2009 $_POST['sdate'] holds the value the user entered right? Well, if your array is set up with keys of sdate, then you can use $array[$_POST['sdate']], but you should always check if the $array has such index, otherwise if someone type "January 1", it would result in an error because $array doesn't have an index at "January 1", but at "January 01". Link to comment https://forums.phpfreaks.com/topic/159627-values-to-dates/#findComment-841982 Share on other sites More sharing options...
486974 Posted May 26, 2009 Author Share Posted May 26, 2009 Thanks Ken2k7 that worked how i want it too, but i cant find a tutorial to help write the script i need for adding the totals depending on how many days are entered would i use the IF statement if 3 is entered then how would i add each array total together. Link to comment https://forums.phpfreaks.com/topic/159627-values-to-dates/#findComment-842578 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.