Jump to content

Values to dates


486974

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

$_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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.