Join David Powers for an in-depth discussion in this video Automatically generating an HTML table from a CSV file, part of Code Clinic: PHP.
- Now that we know how to extract data from a CSV file…it's easy to create a function that will automatically…generate a html table from any CSV file.…I'm going to be using the _assets folder…and another file called cars.csv…both of which you can find in the…Exercise files for this video.…Let's create a new php file…and save it as csv_functions.php…then we'll define that function…and we'll call it tableFromCsv…the first argument will be the file name…and then the second argument will be a boolean value…indicating whether the first line of the CSV file…contains column titles.…
So we'll call that titles.…We'll give it a default value of true…so that'll make it an optional argument.…Before attempting to process a file it's important…to make sure exists and is readable.…So if not file_exists…pass it to $filename…or not is_readable.…In either case we'll just return_false.…
But if we've got a file that we can read…everything else will go in the else block.…We begin by opening the file.…So we'll save the file handle as file…
David introduces challenges and provides an overview of his solutions in PHP. Challenges include topics such as statistical analysis, searching directories for images, and accessing peripheral devices.
Visit other courses in the series to see how to solve the exact same challenges in languages like C#, C++, Java, Python, and Ruby.
Skill Level Intermediate
Q: I'm encountering script errors message with the prime_dates.php file used in the "Priming the date_record column" movie in this course. How can I resolve these errors?
A: To avoid script errors, use bindValue() instead of bindParam() in
Line 9 of the prime_dates.php file. You can also download the latest
copy of the exercise files, which corrects this issue for you. For a
more in-depth explanation of the difference between bindValue() and
bindParam(), check out the "Binding input and output values" video (http://www.lynda.com/PHP-
Q: Why can't I access the Lake Pend Orielle site (http://lpo.dt.navy.mil)?
A: The Lake Pend Orielle site is not accessible in some geographical areas. We have contacted the owner of the server to try to resolve this issue.
Q: I am unable to access the Lake Pend Oreille data from outside the U.S.
A: A static copy of this data is provided here for lynda.com members outside of the U.S
Problem One: Statistical Analysis
Problem Two: Image Analysis
Problem Three: Eight Queens
Problem Four: Accessing Peripherals
Problem Five: Recursion and Directories
Problem Six: Building the Web
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.