Jump to content

Date Search and Print


antonysimpson
 Share

Recommended Posts

hiya, heres the current code:

<body bgcolor="99CCFF"><font face="Verdana"><font size="1"><p><b>01 Jan</b> - A / L<br><b>02 Jan</b> - A / L<br><b>03 Jan</b> - A / L<br><b>04 Jan</b> - A / L<br><b>05 Jan</b> - A / L<br><b>06 Jan</b> - A / L *<br><b>07 Jan</b> - A / L *<br><b>08 Jan</b> - A / L *<br>

I'm wanting a code to put in front of this in php to check the current date and then print the relevent one and the next 7 days after it totalling 8.I'm not quite sure how to go about it. Can anyone help? I cant even get code to just print the date.Thanks,Antony. X

Link to comment
Share on other sites

One resource that will be handy for you is php's mktime function which returns a timestamp that you can use along with php's date function to calculate future and past dates.date()mktime()

<?phpecho "Today is: ". date("F j, Y") . "<br />";// put today's values into our variableslist($sMonth, $sDay, $sYear) =  explode(",", date("n,j,Y"));echo "$sMonth is the Month, $sDay is the Day, $sYear is the Year";echo "<br />";// add 27 days and get the new date$futureDate = date("F j, Y", mktime(0, 0, 0, $sMonth, $sDay + 27, $sYear));echo "Future Date is: $futureDate"; ?>

Hopefully this will give a starting point. :)

Link to comment
Share on other sites

<?phplist($sMonth, $sDay) =  explode(",", date("M,j"));$fil = fopen('dates.txt', r);$dat = fread($fil, filesize('dates.txt')); echo $dat;fclose($fil);?>

This is the code I have for opening and reading a file. Now all I need is a piece of code to get the code to take the $sDay value (e.g. 6) and go down the 6th line in the text file, read and echo the code on that line.After this I was somehow going to use a loop system to something like $sDay +1 then the go to line code in the file. Either that or do it easlier by going for copying the code and adding $sDay + 1 seven other times, what do you think?Can you help me out?Thanks once again!Antony.

Link to comment
Share on other sites

Surely, glad to help out. :) I think I understand the first part of your project but you are losing me here:

After this I was somehow going to use a loop system to something like $sDay +1 then the go to line code in the file. Either that or do it easlier by going for copying the code and adding $sDay + 1 seven other times, what do you think?
This will get the file line:
<?php// adjust for starting line index of 0$captureLine = date("j") - 1;$lines = file('data.txt');foreach ($lines as $line_num => $line) {    if($line_num == $captureLine){      echo "File line ". ($line_num + 1) ." is: $line <br />\n";      break;      }}?>

TGIF . . :)

Link to comment
Share on other sites

I was acutally quite impressed that having a look a few bits and bats of code online I came up with:

<body bgcolor="99CCFF"><font face="Verdana"><font size="1"><?phplist($sMonth, $sDay) =  explode(",", date("M,j"));$fil = fopen('dates.txt', r);$dat = fread($fil, filesize('dates.txt')); $array = file('dates.txt');$sDayed = $sDay - 1;$sDayed2 = $sDay + 1;$sDayed3 = $sDay + 2;$sDayed4 = $sDay + 3;$sDayed5 = $sDay + 4;$sDayed6 = $sDay + 5;$sDayed7 = $sDay + 6;$sDayed8 = $sDay + 7;$sDayed9 = $sDay + 8;echo "$array[$sDayed]";echo "$array[$sDay]";echo "$array[$sDayed2]";echo "$array[$sDayed3]";echo "$array[$sDayed4]";echo "$array[$sDayed5]";echo "$array[$sDayed6]";echo "$array[$sDayed7]";echo "$array[$sDayed8]";echo "$array[$sDayed9]";fclose($fil);?>

Not as easy persay as your code, but was nevertheless impressed with my ability to fix it, lol.Thanks for the reply though :)

Link to comment
Share on other sites

Happy to see that you've had success!That is the cool thing about php, ( I think ) , it's very easy to get used to.I do have a comment, looks like you are opening the file twice, the work is done here:

$array = file('dates.txt');

Unless there is something you have not included these lines create duplicate processes:

$fil = fopen('dates.txt', r);$dat = fread($fil, filesize('dates.txt'));fclose($fil);

Also, an operator that you will get to like is the "++" it increments a variable for you.php operatorsSomething else that you could investigate is the loop:php loopsWhen you are doing the same thing again and again, good to use a loop.Good Job,

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...