• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

import date from file, then compare with today's date

 
Ranch Hand
Posts: 42
Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

For example:
  • Get today's date
  • Open file (on failure, print "File could not be read."
  • ...
  •  
    Marjorie Gyles
    Ranch Hand
    Posts: 42
    Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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.

    For example:

  • 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[0]
    place in the first cell named item
    read second item from data[1]
    place in second cell named priority
    read third item from data[2]
    place in third cell named date
    compare item data[2] to today's date
    if data[2] is past, underline data[0], data[1], data[2]
    if data[2] is today, bold data[0], data[1], data[2]
    otherwise, echo data[0], data[1], data[2]
    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
     
    Roel De Nijs
    Sheriff
    Posts: 11604
    178
    Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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[0], data[1], data[2]. 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



  • Good luck!

    (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)
     
    On top of spaghetti all covered in cheese, there was this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic