Links to an external site.
(opens in new window) Just copy and paste this data into a new text file that you name "booklist.txt" and then upload the file to your Practice Area.
If the user enters
no keyword
to search for and clicks the button, an
asgn4_(yourlastname)_booklist.phpprogram should be called that will return results in
alphabetical order
(by book title) for
all the data in the file,
similar to this...
NOTE: You do NOT need to try to get the results sorted in this step!! (Ignore the heading on the graphic). You will handle the sorting in the next step.
You will need to parse each line from the file into its separate data parts (i.e. title, isbn, type, publication date) and format those into an HTML table row.
IMPORTANT: Get this much to work before moving on to the next steps!! Once this much is working, save a copy of that file off to a "step3" version of the file, e.g. asgn4_perry_step3.php. and then return to the current file, e.g. asgn4_perry.php)
IMPORTANT:
Do NOT use the HTML 'required' attribute on any entry field!
---------------------------------------------------------------------------------------------------------------------------------------------
IF YOU ARE USING YOUR OWN INSTALLED SERVER TO PRACTICE
Do NOT use DOCUMENT_ROOT in your programs that run in the Practice Area.
Even if you start your development with WAMP/MAMP avoid the use of DOCUMENT_ROOT so that you will not have to make changes to your program to run in the Practice Area.
To get this to work, simply create a data directory below the directory where you are running your PHP programs and reference your file like so...
$filename = 'data/booklist.txt';
$fp = fopen($filename, 'r');
---------------------------------------------------------------------------------------------------------------------------------------------
Step 4.
Now code and test the next step, which is to make all the data results be sorted by what the user chooses in the radio button... either ascending or descending
To do this, you will need to...
Read all the data from the file into an array. Note: Make sure to put one entire line, from the file, into one element of the array.
Sort the array in the correct order.
Loop through the data in the array, one element at a time, and parse each line from the file into its separate data parts (i.e. title, isbn, type, publication date) and format those into an HTML table row.
If the user selects the "Descending" radio button, and clicks the button the results would be...
Note:
the 2nd heading reflects that the results are in Reverse Alphabetical Order
IMPORTANT: Get this much to work before moving on to the next steps!! Once this much is working, save a copy of that file off to a "step4" version of the file, e.g. asgn4_perry_step4.php. and then return to the current file, e.g. asgn4_perry.php)
Step 5.
Special Requirement:
For this program you
MUST define a function
that will
receive data for any keyword entered
and what sort order was selected. The function should also set up to receive the users choice of sort order, e.g. function processData($keyword, $sort_order)
The function will load the file into an array, sort the array, and step through all the array elements to produce html code needed to display a table with the proper booklist data.
The function will not do any printing itself and will, instead, return a variable that contains this html code for the table.
The
returned value
will be printed
after the function is called.
So move any code from the Steps completed into this new function.
Note: If the user leaves the field blank, the program should set the keyword variable value to "ALL", as an indicator that all the lines in the file should be read and processed.
For this Step 5, do not process any keyword entered by the user, assume it is blank, set the keyword variable value to "ALL" and pass that to the function.
The function should return a value with all the formatted HTML rows needed to be printed.
After the function is called, use a print statement to print the returned value from the function.
IMPORTANT: Get this much to work before moving on to the next steps!! Once this much is working, save a copy of that file off to a "step5" version of the file, e.g. asgn4_perry_step5.php. and then return to the current file, e.g. asgn4_perry.php)
Step 6.
In this step, you will
send the keyword that the user enters, directly to the function, if they enter anything into the text box. Otherwise, send "ALL" for the keyword value.
If you enter a keyword to search ...
...and click the button, it will match the keywordentered to the book title and return results similar to this...
IMPORTANT TIP:
You
do not need to duplicate all the function code, depending on whether a user enters a keyword or not. Instead, use the string matching functions to determine whether or not the
title
contains a keyword match and, if not,
do not add
that information as an element to the array!
Note: Do not match the the keyword to the whole line (e.g. "Sushi, Anyone?*cooking*1998-06-12*1-7777-7777-x*") just match it to the title (e.g. "Sushi, Anyone?")
Step 7.
Make sure the
headings reflect the key word being used, if any, as I show in the graphics.