I'm trying to import information from a data.txt file. Every third bit of information is a date. I need to compare that date with the current date, then either bold the information if the date is past, or bold it if the date is today's date. Here's what I've been trying to use, but I'm just getting the white screen.
And here is my data.txt file exactly as it appears in the file.
Pay for classes, 3, 01/06/14
Purchase Books, 1, 01/02/14
Purchase groceries, 1, 01/24/14
Sign up for ACM, 3, 02/12/14
Find thesis advisor, 2, 02/25/14
Write thesis intro, 1, 02/25/14
Sign up for "online" course, 3, 01/12/14
This is homework, but I can pull in any sources I want. Any help is appreciated. Thanks in advance.
Roel De Nijs wrote:Can you explain using pseudo-code (or with short sentences) how you would solve this problem? You always start with thinking about the problem and how it could be solved, before you start coding.
Get today's date
Open file (on failure, print "File could not be read."
I've got all that. The only thing I don't know how to do is to compare the dates from the file with today's date. I have done the algorithm, but have no clue how to go about doing it. Any ideas?
in new div begin table
open file data.txt into data
read first item from data
place in the first cell named item
read second item from data
place in second cell named priority
read third item from data
place in third cell named date
compare item data to today's date
if data is past, underline data, data, data
if data is today, bold data, data, data
otherwise, echo data, data, data
continue until all table is filled and eof is reached
in another div echo "Welcome Back!" in <h3>
beneath that echo today's date with day of week
in a third div echo Key in <h3> tag
beneath that list keys to priorities: 1 high, 2 low, 3 medium
end of program
That looks ok! One remark though: you have place in the first cell named item, place in second cell named priority , place in third cell named date and echo data, data, data. So it seems you'll be printing the values twice. Or maybe I have misunderstood.
Marjorie Gyles wrote:The only thing I don't know how to do is to compare the dates from the file with today's date. I have done the algorithm, but have no clue how to go about doing it. Any ideas?
Let's start with the easy part. Reading each line of the comma-separated file and just printing the values in the table. When you have this code finished (and working), we can proceed with the next part of the assignment: comparing dates.
This code (from the PHP manual of the fgetcsv method) will be a very good starting point (as you already have done). Just a few pointers:
absolutely no problem in copying some code from the internet, but always be careful (not all code snippets are of the same quality)
don't just copy, always know (and understand) what you are copying
(If you post the working code to print the file content in the table, just limit the code to the actual snippet, not the whole php file)